]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commit
Avoid using isspace() with signed characters
authorThomas Huth <huth@tuxfamily.org>
Tue, 6 Oct 2020 02:44:57 +0000 (04:44 +0200)
committerThomas Huth <huth@tuxfamily.org>
Tue, 6 Oct 2020 02:44:57 +0000 (04:44 +0200)
commit46bef0513102e1c36dcea20af44f5bb9a6af18dd
treece1dec9c239dc718fd34a8bca4c105eccbaed876
parent2ea70e6bc1c4572834d815690b9b6ee53ad7d8e7
Avoid using isspace() with signed characters

"char" is signed by default on many systems, so when using a "char"
variable as input to isspace(), which takes an "int" parameter, the
parameter gets sign-extended. Now in some libc implementations, the
isspace() function is implemented as a macro that directly indexes
an array for looking up the result - which might go wrong, of course,
if the byte values has the highest bit set. So when compiling Hatari
with Cygwin, there are the following compiler warnings:

.../build68k.c: In function ‘main’:
.../build68k.c:314:18: warning: array subscript has type ‘char’ [-Wchar-subscripts]
  314 |   while (isspace(*opstrp))
      |                  ^~~~~~~
.../build68k.c:319:18: warning: array subscript has type ‘char’ [-Wchar-subscripts]
  319 |    if (!isspace (*osendp))
      |                  ^~~~~~~
.../build68k.c:331:19: warning: array subscript has type ‘char’ [-Wchar-subscripts]
  331 |   while (!isspace(*p++));
      |                   ^~~~

Thus let's make sure to cast the "char" to unsigned first before using
it as parameter to the isspace() function.
build68k.cpp