OSDN Git Service

Applying patch [ 650203 ] Fix char functions in StdAfx.cpp
authorChristian List <list1974@hotmail.com>
Sun, 8 Dec 2002 21:36:31 +0000 (21:36 +0000)
committerChristian List <list1974@hotmail.com>
Sun, 8 Dec 2002 21:36:31 +0000 (21:36 +0000)
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.

Src/StdAfx.cpp

index 3f7bc36..b088a7d 100644 (file)
 
 #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));
 }