aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25
diff options
context:
space:
mode:
authorMax Horn2012-01-28 01:15:49 +0100
committerMax Horn2012-02-15 16:51:37 +0100
commit658080deeda79d20ea40643569fbcb072573e7cf (patch)
treed604bf668909a6db44a1ec83e7c51088a5d85592 /engines/sword25
parent37e5b209a71af725456a42be2605dea28ffceb84 (diff)
downloadscummvm-rg350-658080deeda79d20ea40643569fbcb072573e7cf.tar.gz
scummvm-rg350-658080deeda79d20ea40643569fbcb072573e7cf.tar.bz2
scummvm-rg350-658080deeda79d20ea40643569fbcb072573e7cf.zip
ALL: Avoid using is* macros from ctype.h
On some systems, passing signed chars to macros like isspace() etc. lead to a runtime error. Hence, mark these macros as forbidden by default, and introduce otherwise equivalent alternatives for them.
Diffstat (limited to 'engines/sword25')
-rw-r--r--engines/sword25/util/lua/lbaselib.cpp7
-rw-r--r--engines/sword25/util/lua/llex.cpp26
-rw-r--r--engines/sword25/util/lua/lobject.cpp8
-rw-r--r--engines/sword25/util/lua/lstrlib.cpp2
4 files changed, 18 insertions, 25 deletions
diff --git a/engines/sword25/util/lua/lbaselib.cpp b/engines/sword25/util/lua/lbaselib.cpp
index 3f0b645164..940ddcd4f9 100644
--- a/engines/sword25/util/lua/lbaselib.cpp
+++ b/engines/sword25/util/lua/lbaselib.cpp
@@ -6,10 +6,7 @@
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "common/util.h"
#define lbaselib_c
#define LUA_LIB
@@ -62,7 +59,7 @@ static int luaB_tonumber (lua_State *L) {
luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
n = strtoul(s1, &s2, base);
if (s1 != s2) { /* at least one valid digit? */
- while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */
+ while (isSpace(*s2)) s2++; /* skip trailing spaces */
if (*s2 == '\0') { /* no invalid trailing characters? */
lua_pushnumber(L, (lua_Number)n);
return 1;
diff --git a/engines/sword25/util/lua/llex.cpp b/engines/sword25/util/lua/llex.cpp
index 464ab3ec15..6c7eb78060 100644
--- a/engines/sword25/util/lua/llex.cpp
+++ b/engines/sword25/util/lua/llex.cpp
@@ -5,9 +5,7 @@
*/
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
+#include "common/util.h"
#define llex_c
#define LUA_CORE
@@ -188,7 +186,7 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) {
sprintf(buf, "%.1f", 1.0);
ls->decpoint = '.';
for (i = 0; buf[i]; i++) {
- if (!isspace(static_cast<unsigned char>(buf[i])) && !isdigit(static_cast<unsigned char>(buf[i]))) {
+ if (!isSpace(buf[i]) && !isDigit(buf[i])) {
ls->decpoint = buf[i];
break;
}
@@ -204,13 +202,13 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) {
/* LUA_NUMBER */
static void read_numeral (LexState *ls, SemInfo *seminfo) {
- lua_assert(isdigit(ls->current));
+ lua_assert(isDigit(ls->current));
do {
save_and_next(ls);
- } while (isdigit(ls->current) || ls->current == '.');
+ } while (isDigit(ls->current) || ls->current == '.');
if (check_next(ls, "Ee")) /* `E'? */
check_next(ls, "+-"); /* optional exponent sign */
- while (isalnum(ls->current) || ls->current == '_')
+ while (isAlnum(ls->current) || ls->current == '_')
save_and_next(ls);
save(ls, '\0');
buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
@@ -313,7 +311,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) {
case '\r': save(ls, '\n'); inclinenumber(ls); continue;
case EOZ: continue; /* will raise an error next loop */
default: {
- if (!isdigit(ls->current))
+ if (!isDigit(ls->current))
save_and_next(ls); /* handles \\, \", \', and \? */
else { /* \xxx */
int i = 0;
@@ -321,7 +319,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) {
do {
c = 10*c + (ls->current-'0');
next(ls);
- } while (++i<3 && isdigit(ls->current));
+ } while (++i<3 && isDigit(ls->current));
if (c > UCHAR_MAX)
luaX_lexerror(ls, "escape sequence too large", TK_STRING);
save(ls, c);
@@ -412,7 +410,7 @@ static int llex (LexState *ls, SemInfo *seminfo) {
return TK_DOTS; /* ... */
else return TK_CONCAT; /* .. */
}
- else if (!isdigit(ls->current)) return '.';
+ else if (!isDigit(ls->current)) return '.';
else {
read_numeral(ls, seminfo);
return TK_NUMBER;
@@ -422,21 +420,21 @@ static int llex (LexState *ls, SemInfo *seminfo) {
return TK_EOS;
}
default: {
- if (isspace(ls->current)) {
+ if (isSpace(ls->current)) {
lua_assert(!currIsNewline(ls));
next(ls);
continue;
}
- else if (isdigit(ls->current)) {
+ else if (isDigit(ls->current)) {
read_numeral(ls, seminfo);
return TK_NUMBER;
}
- else if (isalpha(ls->current) || ls->current == '_') {
+ else if (isAlpha(ls->current) || ls->current == '_') {
/* identifier or reserved word */
TString *ts;
do {
save_and_next(ls);
- } while (isalnum(ls->current) || ls->current == '_');
+ } while (isAlnum(ls->current) || ls->current == '_');
ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
luaZ_bufflen(ls->buff));
if (ts->tsv.reserved > 0) /* reserved word? */
diff --git a/engines/sword25/util/lua/lobject.cpp b/engines/sword25/util/lua/lobject.cpp
index 24718931ed..1890aaae68 100644
--- a/engines/sword25/util/lua/lobject.cpp
+++ b/engines/sword25/util/lua/lobject.cpp
@@ -4,11 +4,7 @@
** See Copyright Notice in lua.h
*/
-#include <ctype.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "common/util.h"
#define lobject_c
#define LUA_CORE
@@ -94,7 +90,7 @@ int luaO_str2d (const char *s, lua_Number *result) {
if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */
*result = cast_num(strtoul(s, &endptr, 16));
if (*endptr == '\0') return 1; /* most common case */
- while (isspace(cast(unsigned char, *endptr))) endptr++;
+ while (isSpace(*endptr)) endptr++;
if (*endptr != '\0') return 0; /* invalid trailing characters? */
return 1;
}
diff --git a/engines/sword25/util/lua/lstrlib.cpp b/engines/sword25/util/lua/lstrlib.cpp
index bcc869cb98..ed68a2fa00 100644
--- a/engines/sword25/util/lua/lstrlib.cpp
+++ b/engines/sword25/util/lua/lstrlib.cpp
@@ -5,6 +5,8 @@
*/
+#define FORBIDDEN_SYMBOL_EXCEPTION_ctype_h
+
#include <ctype.h>
#include <stddef.h>
#include <stdio.h>