[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#17081: [PATCH] dfa: avoid undefined behavior

From: Paul Eggert
Subject: bug#17081: [PATCH] dfa: avoid undefined behavior
Date: Sat, 05 Apr 2014 15:10:44 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]