You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by Bill Schindler <de...@bitranch.com> on 2000/02/10 22:26:28 UTC

[Xerces-C] IconvTransService string compare bug

Both of the string compare routines in IconvTransService have problems. As
written, they return equal if one string is a prefix of another. (i.e. "wxyz" is
reported as equal to "wx")

The comparison loop from compareIString() currently looks like this:

  while ((*cptr1 != 0) && (*cptr2 != 0))
  {
     wint_t  wch1 = towupper(*cptr1);
     wint_t  wch2 = towupper(*cptr2);
     if (wch1 < wch2)
         return -1;
     if (wch1 > wch2)
         return 1;

     cptr1++;
     cptr2++;
  }
  return 0;

I believe it would work properly if it was changed to this (compareNIString
would need to be changed in the same manner):

  wint_t wch1 = 0;
  wint_t wch2 = 0;

  while ((*cptr1 != 0) && (*cptr2 != 0))
  {
     wch1 = towupper(*cptr1);
     wch2 = towupper(*cptr2);
     if (wch1 != wch2)
         break;

     cptr1++;
     cptr2++;
  }
  return (wch1 - wch2);

However, I don't know if any code is relying on the current (buggy) method. I
also don't know if changing the return values from -1, 0, 1 to negative-value,
0, positive-value would break anything. A quick grep through the code _seems_ to
indicate the change wouldn't break anything, but...

BTW, this bug causes XMLScanner to generate spurious error messages.



--Bill