Re: Bug in strncasecmp routine (glib source)



On Thu, 6 Jul 2000, Tor Lillqvist wrote:

> I have found a bug in the routine "strncasecmp()" which stays in the
> file "gstrfuncs.c" from the glib stuff. It affects the Windows version
> and some Unix lacking of a native version of this routine.
> 
> Here is a part of this routine:
> 
>   while (n-- && *s1 && *s2)
>     {
>       /* According to A. Cox, some platforms have islower's that
>        * don't work right on non-uppercase
>        */
>       c1 = isupper ((guchar)*s1) ? tolower ((guchar)*s1) : *s1;
>       c2 = isupper ((guchar)*s2) ? tolower ((guchar)*s2) : *s2;
>       if (c1 != c2)
> 	return (c1 - c2);
>       s1++; s2++;
>     }
>   if (n) /* <============= WRONG, should be if(++n) */
>     return (((gint)(guchar) *s1) - ((gint)(guchar) *s2));
>   else
>     return 0;

thanks, fixed by moving the decrement of n into the loop body.

> 
> 					JLH
> 

---
ciaoTJ





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