From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Pip Cet Newsgroups: gmane.emacs.devel Subject: Re: master 64e25cd: More robust NS hex colour string parsing Date: Mon, 8 Jun 2020 12:26:08 +0000 Message-ID: References: <20200608120746.30163.87810@vcs0.savannah.gnu.org> <20200608120747.80E8E20A2E@vcs0.savannah.gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="78324"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org, =?UTF-8?Q?Mattias_Engdeg=C3=A5rd?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Jun 08 14:27:50 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jiGsY-000KFt-Lp for ged-emacs-devel@m.gmane-mx.org; Mon, 08 Jun 2020 14:27:50 +0200 Original-Received: from localhost ([::1]:35656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jiGsX-00031H-Jx for ged-emacs-devel@m.gmane-mx.org; Mon, 08 Jun 2020 08:27:49 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiGrY-00028S-7G for emacs-devel@gnu.org; Mon, 08 Jun 2020 08:26:48 -0400 Original-Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]:37910) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jiGrW-00032x-Kx for emacs-devel@gnu.org; Mon, 08 Jun 2020 08:26:47 -0400 Original-Received: by mail-ot1-x331.google.com with SMTP id n70so976753ota.5 for ; Mon, 08 Jun 2020 05:26:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=F0oMstVS60iOj3x3tW86UciDLTeRPkCti0KyT2OvfK4=; b=MqdPVi8XtvfgGPrzlhrX1DY1b9P64WTSDu0dwGLS2tyV/JnmmxFaH2f8ArjUEiBHuc UKk11KLhxgPOQlyTz1JG9yYstB2z2LeBa26P27JyCUtbfgTg+FbXlxwLuF2Ep2JpPQDc HKZ3EYRwY5wtNIduqxrn2NKFtRGCagVAjS4yAcYzqgVENsL790WD2XYLiNWBdYdz1dSu tFlxjirs5f1mqCkV7KDUgsyJq6OfbwSg+HgS7gsARazN32+Ux4kHVHLROpbpeAkF8B/c OHuV0cFDLwfVvWEdysST7dPpwNAO+yVmvc92SsMnA5gb7qQO5PVyeekfnFedRdCP/hvn eDRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=F0oMstVS60iOj3x3tW86UciDLTeRPkCti0KyT2OvfK4=; b=gJzrAaSKOgRkC8xYScpbwByPtf/uFhbhKQXmVcykZjay/bSzwDXtRfusyHs+k4Q8gs HpH0KFrsDHKec+jU6UJht5u/6yzfxhE9uhYfw6xwzvX+HsZ8jVf7Q6uOv4I1iOE6pi6C 7fGGKFQkh122fHLJ6V++J71Whr9SQldUwd6LvvLUi7CZ6XdJqo65aGnkTz4dm0RgbiUr BpPxZLKOpRCbGZJwvgHpJKt2o5193LVii5tbAXmu1b9PlcLHI7BH1kFjfuuM1eqJ09CR HgDHsyWAm4tm2yjUiZp3AY2gbravd6xsHemAl4MWsELqdpBxOteRp9s/amGnPxK0VD4H YfQg== X-Gm-Message-State: AOAM5319XTczX4THmUREpjr9d4FgIyOJgurlunFGlaGfC7yQsViNgCQu e63TW6/0eWYk978F4GtLRFB6Ze+zfR6LYoDosyovnV/Drn8= X-Google-Smtp-Source: ABdhPJzETWq17qHjULyNhDVTgSLnfo93jQ6CJEiOw6DFsI9JQSRdTgLi/05vG2CD1Di3ftO7/PKsSOsfLnDEoj+EAEw= X-Received: by 2002:a9d:6a44:: with SMTP id h4mr17831274otn.287.1591619204871; Mon, 08 Jun 2020 05:26:44 -0700 (PDT) In-Reply-To: <20200608120747.80E8E20A2E@vcs0.savannah.gnu.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::331; envelope-from=pipcet@gmail.com; helo=mail-ot1-x331.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:252042 Archived-At: On Mon, Jun 8, 2020 at 12:07 PM Mattias Engdeg=C3=A5rd wrote: > branch: master > commit 64e25cde324b2e270acf82958abb59018e67f841 > Author: Mattias Engdeg=C3=A5rd > Commit: Mattias Engdeg=C3=A5rd > > 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 numb= er > 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 =3D (snprintf (hex, sizeof hex, "%s", name + 4) - 2) / 3; > else if (name[0] =3D=3D '#') /* An old X11 format; convert to n= ewer */ > { > - int len =3D (strlen(name) - 1); > - int start =3D (len % 3 =3D=3D 0) ? 1 : len / 4 + 1; > - int i; > - scaling =3D strlen(name+start) / 3; > - for (i =3D 0; i < 3; i++) > - sprintf (hex + i * (scaling + 1), "%.*s/", scaling, > - name + start + i * scaling); > - hex[3 * (scaling + 1) - 1] =3D '\0'; > + int len =3D 0; > + while (isxdigit (name[len + 1])) > + len++; > + if (name[len + 1] =3D=3D '\0' && len >=3D 1 && len <=3D 12 && len = % 3 =3D=3D 0) > + { > + scaling =3D len / 3; > + for (int i =3D 0; i < 3; i++) > + sprintf (hex + i * (scaling + 1), "%.*s/", scaling, > + name + 1 + i * scaling); > + hex[3 * (scaling + 1) - 1] =3D '\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).