From: Beat Bolli <dev+git@drbeat.li>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org, gitster@pobox.com
Subject: Re: [RFC PATCH 6/6] utf8.c: avoid char overflow
Date: Mon, 09 Jul 2018 16:48:28 +0200 [thread overview]
Message-ID: <0ceeb342fec1d0868b81cd64941df53c@drbeat.li> (raw)
In-Reply-To: <nycvar.QRO.7.76.6.1807091513130.75@tvgsbejvaqbjf.bet>
Hi Dscho
Am 09.07.2018 15:14, schrieb Johannes Schindelin:
> Hi Beat,
>
> On Sun, 8 Jul 2018, Beat Bolli wrote:
>
>> In ISO C, char constants must be in the range -128..127. Change the
>> BOM
>> constants to unsigned char to avoid overflow.
>>
>> Signed-off-by: Beat Bolli <dev+git@drbeat.li>
>> ---
>> utf8.c | 10 +++++-----
>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/utf8.c b/utf8.c
>> index d55e20c641..833ce00617 100644
>> --- a/utf8.c
>> +++ b/utf8.c
>> @@ -561,15 +561,15 @@ char *reencode_string_len(const char *in, int
>> insz,
>> #endif
>>
>> static int has_bom_prefix(const char *data, size_t len,
>> - const char *bom, size_t bom_len)
>> + const unsigned char *bom, size_t bom_len)
>> {
>> return data && bom && (len >= bom_len) && !memcmp(data, bom,
>> bom_len);
>> }
>>
>> -static const char utf16_be_bom[] = {0xFE, 0xFF};
>> -static const char utf16_le_bom[] = {0xFF, 0xFE};
>> -static const char utf32_be_bom[] = {0x00, 0x00, 0xFE, 0xFF};
>> -static const char utf32_le_bom[] = {0xFF, 0xFE, 0x00, 0x00};
>> +static const unsigned char utf16_be_bom[] = {0xFE, 0xFF};
>> +static const unsigned char utf16_le_bom[] = {0xFF, 0xFE};
>> +static const unsigned char utf32_be_bom[] = {0x00, 0x00, 0xFE, 0xFF};
>> +static const unsigned char utf32_le_bom[] = {0xFF, 0xFE, 0x00, 0x00};
>
> An alternative approach that might be easier to read (and avoids the
> confusion arising from our use of (signed) chars for strings pretty
> much
> everywhere):
>
> #define FE ((char)0xfe)
> #define FF ((char)0xff)
>
> ...
I have tried this first (without the macros, though), and thought it
looked
really ugly. That's why I chose this solution. The usage is pretty local
and
close to function has_bom_prefix().
Would an explaining comment help?
Beat
next prev parent reply other threads:[~2018-07-09 15:00 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-08 14:43 [RFC PATCH 0/6] Compile cleanly in pedantic mode Beat Bolli
2018-07-08 14:43 ` [RFC PATCH 1/6] connect.h: avoid forward declaration of an enum Beat Bolli
2018-07-08 14:43 ` [RFC PATCH 2/6] refs/refs-internal.h: " Beat Bolli
2018-07-09 18:46 ` Jeff King
2018-07-09 19:30 ` Beat Bolli
2018-07-10 2:15 ` Jeff King
2018-07-08 14:43 ` [RFC PATCH 3/6] convert.c: replace "\e" escapes with "\033" Beat Bolli
2018-07-08 14:43 ` [RFC PATCH 4/6] sequencer.c: avoid empty statements at top level Beat Bolli
2018-07-08 20:54 ` Eric Sunshine
2018-07-08 21:17 ` Philip Oakley
2018-07-09 9:37 ` ig
2018-07-09 21:34 ` Junio C Hamano
2018-07-09 21:37 ` Beat Bolli
2018-07-08 14:43 ` [RFC PATCH 5/6] string-list.c: avoid conversion from void * to function pointer Beat Bolli
2018-07-08 14:43 ` [RFC PATCH 6/6] utf8.c: avoid char overflow Beat Bolli
2018-07-09 13:14 ` Johannes Schindelin
2018-07-09 14:48 ` Beat Bolli [this message]
2018-07-09 15:45 ` Beat Bolli
2018-07-09 16:33 ` Junio C Hamano
2018-07-09 17:56 ` Beat Bolli
2018-07-09 18:18 ` Junio C Hamano
2018-07-09 20:04 ` Johannes Schindelin
2018-07-09 13:40 ` [RFC PATCH 0/6] Compile cleanly in pedantic mode Johannes Schindelin
2018-07-09 16:25 ` Junio C Hamano
2018-07-09 19:25 ` [PATCH " Beat Bolli
2018-07-09 20:25 ` Beat Bolli
2018-07-09 21:45 ` Junio C Hamano
2018-07-09 21:47 ` Beat Bolli
2018-07-10 7:34 ` Beat Bolli
2018-07-11 15:42 ` Junio C Hamano
2018-07-12 13:25 ` Johannes Schindelin
2018-07-12 15:40 ` Junio C Hamano
2018-07-09 19:25 ` [PATCH 1/6] connect.h: avoid forward declaration of an enum Beat Bolli
2018-07-09 19:25 ` [PATCH 2/6] refs/refs-internal.h: " Beat Bolli
2018-07-09 19:25 ` [PATCH 3/6] convert.c: replace "\e" escapes with "\033" Beat Bolli
2018-07-09 19:25 ` [PATCH 4/6] sequencer.c: avoid empty statements at top level Beat Bolli
2018-07-09 21:37 ` Junio C Hamano
2018-07-09 19:25 ` [PATCH 5/6] string-list.c: avoid conversion from void * to function pointer Beat Bolli
2018-07-09 19:25 ` [PATCH 6/6] utf8.c: avoid char overflow Beat Bolli
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0ceeb342fec1d0868b81cd64941df53c@drbeat.li \
--to=dev+git@drbeat.li \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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 public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).