[PATCH v2] Fix warning in isspace() and isdigit().

Aschref Ben-Thabet aschref.ben-thabet at embedded-brains.de
Mon Jul 20 14:44:01 UTC 2020


From: Aschref Ben Thabet <aschref.ben-thabet at embedded-brains.de>

The warning may be because you're passing a char to the isspace() macro. The
implementation of isspace() may be via array indexing. (The argument to the
isspace()/isdegit() macro is defined to be an unsigned char the value of which
can fit in an unsignedchar).

at ctype.h in GNU libc, and while there's a complicated mess of macros and
functions, somewhere in the definition of isspace() there's an array being
indexed.

See if isspace((unsigned char) *str) gets rid of the warning.

The line array[c] is very likely a bug, because the type char can be signed or
unsigned—it's up to the compiler. If char is signed, then it's possible for c
to be negative, in which case accessing a negative array index leads to
Undefined Behavior.
---
 cpukit/libdl/rtl-archive.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cpukit/libdl/rtl-archive.c b/cpukit/libdl/rtl-archive.c
index eb7641b034..8f280157ff 100644
--- a/cpukit/libdl/rtl-archive.c
+++ b/cpukit/libdl/rtl-archive.c
@@ -516,13 +516,13 @@ rtems_rtl_archives_load_config (rtems_rtl_archives* archives)
       {
         size_t ls = strlen (&s[r]);
         size_t b = 0;
-        while (b < ls && isspace (s[r + b]))
+        while (b < ls && isspace((unsigned char)(s[r + b])))
         {
           s[r + b] = '\0';
           ++b;
         }
         b = ls - 1;
-        while (b > 0 && isspace (s[r + b]))
+        while (b > 0 && isspace((unsigned char)(s[r + b])))
         {
           s[r + b] = '\0';
           --b;
-- 
2.26.2



More information about the devel mailing list