ref: 6c590f720cbdbf0a259f6edfc3fe9191cc0dc3da
parent: 4e98c124ebf610c08f4f9a36ae19bcf8e3f6abed
author: asau <asau@ficl.sf.net>
date: Sun Sep 12 10:07:32 CDT 2010
Avoid potential problems with character classification.
--- a/primitives.c
+++ b/primitives.c
@@ -4,7 +4,7 @@
** ANS Forth CORE word-set written in C
** Author: John Sadler (john_sadler@alum.mit.edu)
** Created: 19 July 1997
-** $Id: primitives.c,v 1.2 2010/09/10 11:16:07 asau Exp $
+** $Id: primitives.c,v 1.3 2010/09/12 15:07:32 asau Exp $
*******************************************************************/
/*
** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
@@ -409,7 +409,7 @@
break;
}
- desiredLength = isdigit(*format);
+ desiredLength = isdigit((unsigned char)*format);
if (desiredLength)
{
desiredLength = strtoul(format, &format, 10);
--- a/utility.c
+++ b/utility.c
@@ -174,8 +174,8 @@
while (*cp)
{
- if (isupper(*cp))
- *cp = (char)tolower(*cp);
+ if (isupper((unsigned char)*cp))
+ *cp = (char)tolower((unsigned char)*cp);
cp++;
}
@@ -193,7 +193,7 @@
for (; 0 < count; ++cp1, ++cp2, --count)
{
- i = tolower(*cp1) - tolower(*cp2);
+ i = tolower((unsigned char)*cp1) - tolower((unsigned char)*cp2);
if (i != 0)
return i;
else if (*cp1 == '\0')
@@ -213,7 +213,7 @@
{
FICL_ASSERT(NULL, cp);
- while ((cp != end) && isspace(*cp))
+ while ((cp != end) && isspace((unsigned char)*cp))
cp++;
return cp;
--- a/vm.c
+++ b/vm.c
@@ -3,7 +3,7 @@
** Forth Inspired Command Language - virtual machine methods
** Author: John Sadler (john_sadler@alum.mit.edu)
** Created: 19 July 1997
-** $Id: vm.c,v 1.14 2010/08/12 13:57:22 asau Exp $
+** $Id: vm.c,v 1.15 2010/09/12 15:07:32 asau Exp $
*******************************************************************/
/*
** This file implements the virtual machine of Ficl. Each virtual
@@ -1199,14 +1199,14 @@
uMin = (u1 < u2)? u1 : u2;
for ( ; (uMin > 0) && (n == 0); uMin--)
{
- char c1 = *cp1++;
- char c2 = *cp2++;
+ int c1 = (unsigned char)*cp1++;
+ int c2 = (unsigned char)*cp2++;
if (i)
{
- c1 = (char)tolower(c1);
- c2 = (char)tolower(c2);
+ c1 = tolower(c1);
+ c2 = tolower(c2);
}
- n = (int)(c1 - c2);
+ n = (c1 - c2);
}
if (n == 0)
@@ -2401,7 +2401,7 @@
if (trace == stop)
break;
c = *trace;
- if (isspace(c))
+ if (isspace((unsigned char)c))
break;
length++;
trace++;
@@ -2409,7 +2409,7 @@
FICL_STRING_SET_LENGTH(s, length);
- if ((trace != stop) && isspace(c)) /* skip one trailing delimiter */
+ if ((trace != stop) && isspace((unsigned char)c)) /* skip one trailing delimiter */
trace++;
ficlVmUpdateTib(vm, trace);