From: Janne Kulmala Date: Tue, 17 Apr 2012 07:53:53 +0000 (+0300) Subject: load: Avoid unexpected behaviour in macro expansion X-Git-Tag: v2.4-moonshot~1^2~10^2~9 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=jansson.git;a=commitdiff_plain;h=bd72efbd8073c0e14fa3dacf7da2883c9ea70952 load: Avoid unexpected behaviour in macro expansion Macros can be dangerous if the inserted arguments are not properly parenthesised. As macro expansion does a simple replacement, inserting a certain expression can cause the evaluation order of the macro expression to change. --- diff --git a/src/load.c b/src/load.c index 70a1ac2..a904599 100644 --- a/src/load.c +++ b/src/load.c @@ -32,12 +32,12 @@ #define TOKEN_NULL 261 /* Locale independent versions of isxxx() functions */ -#define l_isupper(c) ('A' <= c && c <= 'Z') -#define l_islower(c) ('a' <= c && c <= 'z') +#define l_isupper(c) ('A' <= (c) && (c) <= 'Z') +#define l_islower(c) ('a' <= (c) && (c) <= 'z') #define l_isalpha(c) (l_isupper(c) || l_islower(c)) -#define l_isdigit(c) ('0' <= c && c <= '9') +#define l_isdigit(c) ('0' <= (c) && (c) <= '9') #define l_isxdigit(c) \ - (l_isdigit(c) || 'A' <= c || c <= 'F' || 'a' <= c || c <= 'f') + (l_isdigit(c) || 'A' <= (c) || (c) <= 'F' || 'a' <= (c) || (c) <= 'f') /* Read one byte from stream, convert to unsigned char, then int, and return. return EOF on end of file. This corresponds to the