GNU bug report logs -
#17081
[PATCH] dfa: avoid undefined behavior
Previous Next
Reported by: Paul Eggert <eggert <at> CS.UCLA.EDU>
Date: Mon, 24 Mar 2014 06:07:01 UTC
Severity: normal
Tags: patch
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Paolo Bonzini wrote:
\
>> + size_t nbytes = mbrtowc (&_wc, lexptr, lexleft, &mbs); \
>> + bool valid_char = 1 <= nbytes && nbytes < (size_t) -2; \
>
> I find these conditionals complicated to follow.
Yes, that identifier 'valid_char' was a confusing choice; as you noted,
the character is valid even when nbytes is zero.
> I believe you should have simply
>
> bool valid_char = nbytes < (size_t) -2;
>
> or better:
>
>> + if (! valid_char) \
>
> if (nbytes >= (size_t) -2)
That wouldn't do, because when mbrtowc returns 0 the caller still needs
to advance the pointer by 1 to get past the null byte, just as it needs
to advance by 1 if mbrtowc returns (size_t) -2 or (size_t) -1.
> I see this patch has been committed already. Can you please submit a followup?
There was a followup patch, in commit 2b9c57c, and the code's changed so
that it no longer has a 'valid_char' local. Perhaps it's clear enough now.
This bug report was last modified 11 years and 107 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.