nitpicking on strcasestr.c

From: Andrea Campi <andrea+freebsd_current_at_webcom.it>
Date: Wed, 13 Oct 2004 14:28:54 +0200
Hi,

I just noticed a couple of things in strcasestr.c which cause
warnings on ${OTHER_OS}, but still apply to us:


char *
strcasestr(s, find)
	const char *s, *find;
{
	char c, sc;
	size_t len;

	if ((c = *find++) != 0) {
		c = tolower((unsigned char)c);
		len = strlen(find);
		do {
			do {
				if ((sc = *s++) == 0)
					return (NULL);
			} while ((char)tolower((unsigned char)sc) != c);
		} while (strncasecmp(s, find, len) != 0);
		s--;
	}
	return ((char *)s);
}


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?

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....

Bye,
	Andrea

-- 
               Speak softly and carry a cellular phone.
Received on Wed Oct 13 2004 - 10:28:56 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:17 UTC