all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@gmail.com>
To: emacs-devel@gnu.org, "Mattias Engdegård" <mattiase@acm.org>
Subject: Re: master 64e25cd: More robust NS hex colour string parsing
Date: Mon, 8 Jun 2020 12:26:08 +0000	[thread overview]
Message-ID: <CAOqdjBfwzA205fJ75RhFivfNWteCPbwBM4Op+1+pewGZ2e8TiA@mail.gmail.com> (raw)
In-Reply-To: <20200608120747.80E8E20A2E@vcs0.savannah.gnu.org>

On Mon, Jun 8, 2020 at 12:07 PM Mattias Engdegård
<mattiase@savannah.gnu.org> wrote:
> branch: master
> commit 64e25cde324b2e270acf82958abb59018e67f841
> Author: Mattias Engdegård <mattiase@acm.org>
> Commit: Mattias Engdegård <mattiase@acm.org>
>
>     More robust NS hex colour string parsing
>
>     Invalid arguments to color-values, such as "#abcdefg" or "#1234", or
>     valid ones like "#111222333", should not yield nonsense values.
>
>     * src/nsterm.m (ns_get_color):
>     Only accept "#RGB" strings with 1-4 digits per components, equal number
>     of digits each, and no trailing characters.  Parse 12-bit colours
>     correctly.
> ---
>  src/nsterm.m | 21 ++++++++++++---------
>  1 file changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/src/nsterm.m b/src/nsterm.m
> index 1953138..3dc7e1d 100644
> --- a/src/nsterm.m
> +++ b/src/nsterm.m
> @@ -2399,20 +2399,23 @@ ns_get_color (const char *name, NSColor **col)
>      scaling = (snprintf (hex, sizeof hex, "%s", name + 4) - 2) / 3;
>    else if (name[0] == '#')        /* An old X11 format; convert to newer */
>      {
> -      int len = (strlen(name) - 1);
> -      int start = (len % 3 == 0) ? 1 : len / 4 + 1;
> -      int i;
> -      scaling = strlen(name+start) / 3;
> -      for (i = 0; i < 3; i++)
> -       sprintf (hex + i * (scaling + 1), "%.*s/", scaling,
> -                name + start + i * scaling);
> -      hex[3 * (scaling + 1) - 1] = '\0';
> +      int len = 0;
> +      while (isxdigit (name[len + 1]))
> +        len++;
> +      if (name[len + 1] == '\0' && len >= 1 && len <= 12 && len % 3 == 0)
> +        {
> +          scaling = len / 3;
> +          for (int i = 0; i < 3; i++)
> +            sprintf (hex + i * (scaling + 1), "%.*s/", scaling,
> +                     name + 1 + i * scaling);
> +          hex[3 * (scaling + 1) - 1] = '\0';
> +        }
>      }

I believe there's very similar code for the X case, where we also
translate #fff to rgb:f/f/f. That code has annoyed me lately by
producing nonsensical GCC warnings, maybe you'd like to replace it
with yours? Having two different versions of this seems superfluous
(I'm not doubting the correctness of your version, which I guess means
I'm doubting that of mine).



       reply	other threads:[~2020-06-08 12:26 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200608120746.30163.87810@vcs0.savannah.gnu.org>
     [not found] ` <20200608120747.80E8E20A2E@vcs0.savannah.gnu.org>
2020-06-08 12:26   ` Pip Cet [this message]
2020-06-08 16:15     ` master 64e25cd: More robust NS hex colour string parsing Mattias Engdegård
2020-06-12 16:59     ` Mattias Engdegård
2020-06-12 17:33       ` Eli Zaretskii
2020-06-12 19:00         ` Mattias Engdegård
2020-06-12 19:11           ` Eli Zaretskii
2020-06-12 19:25             ` Eli Zaretskii
2020-06-13 10:17             ` Mattias Engdegård
2020-06-13 11:59               ` Eli Zaretskii
2020-06-13 15:39                 ` Mattias Engdegård
2020-06-13 15:58                   ` Eli Zaretskii
2020-06-13 16:44                     ` Mattias Engdegård
2020-06-13 17:09                       ` Eli Zaretskii
2020-06-13 17:29                         ` Mattias Engdegård
2020-06-13 17:35                           ` Eli Zaretskii
2020-06-13 17:56                             ` Mattias Engdegård
2020-06-13 18:40                               ` Eli Zaretskii
2020-06-15  8:31                                 ` Mattias Engdegård
2020-06-21  7:48                                   ` Mattias Engdegård
2020-06-21 14:59                                     ` Eli Zaretskii
2020-06-21 19:23                                       ` Mattias Engdegård
2020-06-13 19:15                               ` Basil L. Contovounesios
2020-06-12 19:15           ` Pip Cet
2020-06-13 10:40             ` Mattias Engdegård
2020-06-12 18:33       ` Basil L. Contovounesios
2020-06-13 17:52         ` Mattias Engdegård

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOqdjBfwzA205fJ75RhFivfNWteCPbwBM4Op+1+pewGZ2e8TiA@mail.gmail.com \
    --to=pipcet@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=mattiase@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.