[PATCH] 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).

Aschref Ben-Thabet aschref.ben-thabet at embedded-brains.de
Mon Jul 20 13:53:13 UTC 2020


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

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 ++--
 testsuites/fstests/fsdosfsname01/init.c | 2 +-
 2 files changed, 3 insertions(+), 3 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;
diff --git a/testsuites/fstests/fsdosfsname01/init.c b/testsuites/fstests/fsdosfsname01/init.c
index 3689da8eed..8eb7982e22 100644
--- a/testsuites/fstests/fsdosfsname01/init.c
+++ b/testsuites/fstests/fsdosfsname01/init.c
@@ -429,7 +429,7 @@ static void test_creating_invalid_directories( void )
               sizeof( dirname ),
               "%s/%s",
               MOUNT_DIR,
-              DIRECTORY_NAMES_INVALID[index] );
+               DIRECTORY_NAMES_INVALID[index]);
     rc = mkdir( dirname, S_IRWXU | S_IRWXG | S_IRWXO );
     rtems_test_assert( rc == -1 );
   }
-- 
2.26.2



More information about the devel mailing list