Char functions in StdAfx.cpp do not handle non-ASCII
data correctly; they suffer from sign-extension bug
which can cause GPF. A signed char gets
converted (sign-extended !) to a signed int, which then
gets converted back to unsigned, and now it is off
by billions.
#include "stdafx.h"
+// fix any nonascii characters
+// which got sign-extended to become negative integers
+int normch(int c)
+{
+ return (unsigned char)(char)c;
+}
+
int
xisspecial (int c)
{
- return (unsigned) c > (unsigned) _T ('\x7f') || c == _T ('_');
+ return normch(c) > (unsigned) _T ('\x7f') || c == _T ('_');
// return _tcschr (_T ("ì\9aèø\9eýáíéóúùï\9dò¾àå\9cäëöüÌ\8aÈØ\8eÝÁÍÉ´OÚÙÏ\8dÒ¼ÀÅ\8cÄËÖܧ"), c) != NULL;
}
int
xisalpha (int c)
{
- return isalpha (c) || xisspecial (c);
+ return isalpha (normch(c)) || xisspecial (normch(c));
}
int
xisalnum (int c)
{
- return isalnum (c) || xisspecial (c);
+ return isalnum (normch(c)) || xisspecial (normch(c));
}