Minor correctness issue with l_str2d's use of ltolower

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Minor correctness issue with l_str2d's use of ltolower

Ahmed Charles
ltolower could be enhanced with a check such as:

#define ltolower(c)     check_exp((c) >= 'A' && (c) <= 'Z' || (c) >= 'a' && (c) <= 'z', ((c) | ('A' ^ 'a')))

Running the test suite with this reveals that the following code in l_str2d is incorrect:

const char *pmode = strpbrk(s, ".xXnN");

It should be:

const char *pmode = strpbrk(s, "xXnN");

Due to the following line calling ltolower:

int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0;

Note: this doesn't change the code's behavior at all, because 0 is equivalent to '.' (or 46, which is the value returned by ltolower('.')) when doing the subsequent checks against mode. It's mostly just cause for confusion.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Minor correctness issue with l_str2d's use of ltolower

Roberto Ierusalimschy
> ltolower could be enhanced with a check such as:
>
> #define ltolower(c)     check_exp((c) >= 'A' && (c) <= 'Z' || (c) >= 'a' && (c) <= 'z', ((c) | ('A' ^ 'a')))
>
> [...]
>
> Note: this doesn't change the code's behavior at all, because 0 is equivalent to '.' (or 46, which is the value returned by ltolower('.')) when doing the subsequent checks against mode. It's mostly just cause for confusion.

Thanks for the feedback.

-- Roberto