svn commit: r225336 - user/gabor/grep/trunk/regex

Andrey Chernov ache at FreeBSD.ORG
Fri Sep 2 17:53:38 UTC 2011


On Fri, Sep 02, 2011 at 04:50:24PM +0000, Gabor Kovesdan wrote:
>   - Do not cast to unsigned char because it can cause a segfault

> -      fg->qsBc[(unsigned)fg->pattern[i]] = fg->len - i;			\
> +      fg->qsBc[fg->pattern[i]] = fg->len - i;				\

> -          fg->qsBc[(unsigned)c] = fg->len - i;				\
> +          fg->qsBc[c] = fg->len - i;					\

I see there was cast to (unsigned) not to (unsigned char). They works 
in very different ways. To be safe: never cast char to (unsigned), only to 
(unsigned char).

If 8bit is set in the character, i.e. it is negative, cast to (unsigned) 
provides very big values because it promotes to (int) first and then makes 
(unsigned) from that (int).

-- 
http://ache.vniz.net/


More information about the svn-src-user mailing list