From 13c7a4265a1024903b120f3bf11cd89ff9f4477a Mon Sep 17 00:00:00 2001 From: Christof Meerwald Date: Wed, 17 Dec 2025 16:39:43 +0000 Subject: [PATCH] jam: Fix isspace/isalnum/tolower/... usage The value passed in must be representable as an unsigned char or equal to the value of the macro EOF. NetBSD 11+ is actually enforcing this. Change-Id: I9a7eada7c0c1ae206aa6810027a2b02742b72934 Reviewed-on: https://review.haiku-os.org/c/buildtools/+/10127 Reviewed-by: waddlesplash --- jam/execunix.c | 4 ++-- jam/expand.c | 4 ++-- jam/option.c | 2 +- jam/regexp.c | 6 +++--- jam/scan.c | 7 ++++--- jam/timestamp.c | 4 ++-- jam/variable.c | 4 ++-- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/jam/execunix.c b/jam/execunix.c index e19293ba27..f479c6350e 100644 --- a/jam/execunix.c +++ b/jam/execunix.c @@ -154,12 +154,12 @@ execcmd( /* Trim leading, ending white space */ - while( isspace( *string ) ) + while( isspace( (unsigned char)*string ) ) ++string; p = strchr( string, '\n' ); - while( p && isspace( *p ) ) + while( p && isspace( (unsigned char)*p ) ) ++p; /* If multi line, or too long, or JAMSHELL is set, write to bat file. */ diff --git a/jam/expand.c b/jam/expand.c index b6ef564f48..f8a20dcdc7 100644 --- a/jam/expand.c +++ b/jam/expand.c @@ -538,11 +538,11 @@ var_edit_shift( if( edits->upshift ) { for( ; *out; ++out ) - *out = toupper( *out ); + *out = toupper( (unsigned char)*out ); } else if( edits->downshift ) { for( ; *out; ++out ) - *out = tolower( *out ); + *out = tolower( (unsigned char)*out ); } } diff --git a/jam/option.c b/jam/option.c index ad3825f191..1d2ee12882 100644 --- a/jam/option.c +++ b/jam/option.c @@ -35,7 +35,7 @@ getoptions( { char *arg; - if( argv[i][0] != '-' || !isalpha( argv[i][1] ) ) + if( argv[i][0] != '-' || !isalpha( (unsigned char)argv[i][1] ) ) break; if( !optc-- ) diff --git a/jam/regexp.c b/jam/regexp.c index a1fcc181d6..c824258f05 100644 --- a/jam/regexp.c +++ b/jam/regexp.c @@ -917,16 +917,16 @@ regmatch( char *prog ) break; case WORDA: /* Must be looking at a letter, digit, or _ */ - if ((!isalnum(*reginput)) && *reginput != '_') + if ((!isalnum((unsigned char)*reginput)) && *reginput != '_') return(0); /* Prev must be BOL or nonword */ if (reginput > regbol && - (isalnum(reginput[-1]) || reginput[-1] == '_')) + (isalnum((unsigned char)reginput[-1]) || reginput[-1] == '_')) return(0); break; case WORDZ: /* Must be looking at non letter, digit, or _ */ - if (isalnum(*reginput) || *reginput == '_') + if (isalnum((unsigned char)*reginput) || *reginput == '_') return(0); /* We don't care what the previous char was */ break; diff --git a/jam/scan.c b/jam/scan.c index d544e67233..4d0d62323e 100644 --- a/jam/scan.c +++ b/jam/scan.c @@ -287,7 +287,7 @@ yylex() { /* Skip past white space */ - while( c != EOF && isspace( c ) ) + while( c != EOF && isspace( (unsigned char)c ) ) c = yychar(); /* Not a comment? Swallow up comment line. */ @@ -315,7 +315,7 @@ yylex() while( c != EOF && b < buf + sizeof( buf ) && - ( inquote || !isspace( c ) ) ) + ( inquote || !isspace( (unsigned char)c ) ) ) { if( c == '"' ) { @@ -369,7 +369,8 @@ yylex() *b = 0; yylval.type = ARG; - if( !notkeyword && !( isalpha( *buf ) && scanmode == SCAN_PUNCT ) ) + if( !notkeyword && + !( isalpha( (unsigned char)*buf ) && scanmode == SCAN_PUNCT ) ) { for( k = keywords; k->word; k++ ) if( *buf == *k->word && !strcmp( k->word, buf ) ) diff --git a/jam/timestamp.c b/jam/timestamp.c index 8b590a83c1..d0d31cc2b0 100644 --- a/jam/timestamp.c +++ b/jam/timestamp.c @@ -72,7 +72,7 @@ timestamp( char path[ MAXJPATH ]; char *p = path; - do *p++ = tolower( *target ); + do *p++ = tolower( (unsigned char)*target ); while( *target++ ); target = path; @@ -175,7 +175,7 @@ time_enter( char path[ MAXJPATH ]; char *p = path; - do *p++ = tolower( *target ); + do *p++ = tolower( (unsigned char)*target ); while( *target++ ); target = path; diff --git a/jam/variable.c b/jam/variable.c index 7a5b4f4442..6bd09eae20 100644 --- a/jam/variable.c +++ b/jam/variable.c @@ -152,7 +152,7 @@ var_string( /* Copy white space */ - while( isspace( *in ) ) + while( isspace( (unsigned char)*in ) ) { if( out >= oute ) return -1; @@ -164,7 +164,7 @@ var_string( /* Copy non-white space, watching for variables */ - while( *in && !isspace( *in ) ) + while( *in && !isspace( (unsigned char)*in ) ) { if( out >= oute ) return -1;