Hi!

When using gnuchess on NetBSD to build the 'book' based on
book_1.02.pgn (for the gnuchess-book pkgsrc package), there is a
warning and a segfault, see e.g.

https://releng.netbsd.org/pkgreports/shadow/HEAD/NetBSD-11.0-x86_64/20260916.0427/gnuchess-book-1.02nb1/build.log

ctype(3) isspace: invalid input: 256

The problem is that NetBSD is especially picky about valid ctype(3)
function arguments. The standards only allow values in the 'unsigned
char' range and EOF. More details are at

https://man.netbsd.org/ctype.3

This often causes problems with UTF-8 data passed unchecked as 'char',
which is 'signed char' on most NetBSD platforms.

The standard workaround is to case the arguments to 'unsigned char',
as the attached patches against gnuchess 6.3.0 do.

Please take a look at fixing this.

Thanks,
 Thomas
$NetBSD$

Fix ctype(3) usage.

--- src/adapter/pgn.cpp.orig	2026-09-21 08:50:11.609305395 +0000
+++ src/adapter/pgn.cpp
@@ -545,7 +545,7 @@ static void pgn_skip_blanks(pgn_t * pgn) {
 
       if (false) {
 
-      } else if (isspace(pgn->char_hack)) {
+      } else if (isspace((unsigned char)pgn->char_hack)) {
 
          // skip white space
 
$NetBSD$

Fix ctype(3) usage.

--- src/frontend/cmd.cc.orig	2026-09-21 08:51:06.915496850 +0000
+++ src/frontend/cmd.cc
@@ -69,14 +69,14 @@ static void split_input(void)
 
   for (k = 0, s = r = inputstr; k < TOKENS; ++k) {
     /* Skip leading whitespace */
-    while (isspace(*s)) s++;
+    while (isspace((unsigned char)*s)) s++;
     token[k] = s;
     /* Skip token */
-    while (*s && !isspace(*s)) r = s++;
+    while (*s && !isspace((unsigned char)*s)) r = s++;
   }
   while (*s) {
-    while (isspace(*s)) s++;
-    while (*s && !isspace(*s)) r = s++;
+    while (isspace((unsigned char)*s)) s++;
+    while (*s && !isspace((unsigned char)*s)) r = s++;
   }
   r[1] = '\0';
 }
@@ -87,10 +87,10 @@ static int tokeneq(const char *s, const char *t)
  */
 static int tokeneq(const char *s, const char *t)
 {
-  while (*s && *t && !isspace(*s) && !isspace(*t)) {
+  while (*s && *t && !isspace((unsigned char)*s) && !isspace((unsigned char)*t)) {
     if (*s++ != *t++) return 0;
   }
-  return (!*s || isspace(*s)) && (!*t || isspace(*t));
+  return (!*s || isspace((unsigned char)*s)) && (!*t || isspace((unsigned char)*t));
 }
 
 /*
$NetBSD$

Fix ctype(3) usage.

--- src/frontend/move.cc.orig	2026-09-21 08:50:44.746178707 +0000
+++ src/frontend/move.cc
@@ -559,7 +559,7 @@ leaf * ValidateMove (char *s, char *cleanMove)
    p = mvstr;
    do
    {
-      if (*s != 'x' && *s != '+' && *s != '=' && !isspace(*s))
+      if (*s != 'x' && *s != '+' && *s != '=' && !isspace((unsigned char)*s))
          *p++ = *s;
    } while (*s++ != '\0' );
 

Reply via email to