nitpicking on strcasestr.c

Thomas Dickey dickey at radix.net
Wed Oct 13 05:50:34 PDT 2004


On Wed, Oct 13, 2004 at 02:28:54PM +0200, Andrea Campi wrote:
 
> We have two calls to tolower(); the first doesn't cast the result
> at all, the second one casts it to char. Shouldn't the first one be
> changed also?

man tolower (Solaris - but if FreeBSD differs, someone has a problem):

NAME
     tolower - transliterate upper-case characters to lower-case

SYNOPSIS
     #include <ctype.h>

     int tolower(int c);
 
> Actually, my first feeling was to change both to unsigned char, but
> I'm sure somebody could go to great lenghts to explain to me how the
> code as it stands is carefully crafted to work whether chars are signed
> or unsigned....

Noting that tolower() returns an int, and char's sign is unspecified,
either changing the type for c (to int) or adding a cast is a good
idea.  Adding casts is generally a bad idea.

-- 
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-current/attachments/20041013/a91941e0/attachment.bin


More information about the freebsd-current mailing list