Skip to content

Commit 282852e

Browse files
author
D. Richard Hipp
committed
Fix uses of ctype functions (ex: isspace()) on signed characters in test
programs and in some obscure extensions. No changes to the core.
1 parent bff1cff commit 282852e

File tree

17 files changed

+115
-86
lines changed

17 files changed

+115
-86
lines changed

autoconf/tea/win/nmakehlp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,8 @@ SubstituteFile(
603603
sp = fopen(substitutions, "rt");
604604
if (sp != NULL) {
605605
while (fgets(szBuffer, cbBuffer, sp) != NULL) {
606-
char *ks, *ke, *vs, *ve;
607-
ks = szBuffer;
606+
unsigned char *ks, *ke, *vs, *ve;
607+
ks = (unsigned char*)szBuffer;
608608
while (ks && *ks && isspace(*ks)) ++ks;
609609
ke = ks;
610610
while (ke && *ke && !isspace(*ke)) ++ke;
@@ -613,7 +613,7 @@ SubstituteFile(
613613
ve = vs;
614614
while (ve && *ve && !(*ve == '\r' || *ve == '\n')) ++ve;
615615
*ke = 0, *ve = 0;
616-
list_insert(&substPtr, ks, vs);
616+
list_insert(&substPtr, (char*)ks, (char*)vs);
617617
}
618618
fclose(sp);
619619
}

ext/fts1/fts1.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@ static int getVarint32(const char *p, int *pi){
205205
*/
206206
/* TODO(shess) Is __isascii() a portable version of (c&0x80)==0? */
207207
static int safe_isspace(char c){
208-
return (c&0x80)==0 ? isspace(c) : 0;
208+
return (c&0x80)==0 ? isspace((unsigned char)c) : 0;
209209
}
210210
static int safe_tolower(char c){
211-
return (c&0x80)==0 ? tolower(c) : c;
211+
return (c&0x80)==0 ? tolower((unsigned char)c) : c;
212212
}
213213
static int safe_isalnum(char c){
214-
return (c&0x80)==0 ? isalnum(c) : 0;
214+
return (c&0x80)==0 ? isalnum((unsigned char)c) : 0;
215215
}
216216

217217
typedef enum DocListType {

ext/fts1/simple_tokenizer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static int simpleNext(
138138
** case-insensitivity.
139139
*/
140140
char ch = c->pCurrent[ii];
141-
c->zToken[ii] = (unsigned char)ch<0x80 ? tolower(ch) : ch;
141+
c->zToken[ii] = (unsigned char)ch<0x80 ? tolower((unsigned char)ch):ch;
142142
}
143143
c->zToken[n] = '\0';
144144
*ppToken = c->zToken;

ext/misc/amatch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,10 +816,10 @@ static const char *amatchValueOfKey(const char *zKey, const char *zStr){
816816
int i;
817817
if( nStr<nKey+1 ) return 0;
818818
if( memcmp(zStr, zKey, nKey)!=0 ) return 0;
819-
for(i=nKey; isspace(zStr[i]); i++){}
819+
for(i=nKey; isspace((unsigned char)zStr[i]); i++){}
820820
if( zStr[i]!='=' ) return 0;
821821
i++;
822-
while( isspace(zStr[i]) ){ i++; }
822+
while( isspace((unsigned char)zStr[i]) ){ i++; }
823823
return zStr+i;
824824
}
825825

ext/misc/closure.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,10 @@ static const char *closureValueOfKey(const char *zKey, const char *zStr){
486486
int i;
487487
if( nStr<nKey+1 ) return 0;
488488
if( memcmp(zStr, zKey, nKey)!=0 ) return 0;
489-
for(i=nKey; isspace(zStr[i]); i++){}
489+
for(i=nKey; isspace((unsigned char)zStr[i]); i++){}
490490
if( zStr[i]!='=' ) return 0;
491491
i++;
492-
while( isspace(zStr[i]) ){ i++; }
492+
while( isspace((unsigned char)zStr[i]) ){ i++; }
493493
return zStr+i;
494494
}
495495

ext/misc/spellfix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,7 @@ static char *spellfix1Dequote(const char *zIn){
18511851
char *zOut;
18521852
int i, j;
18531853
char c;
1854-
while( isspace(zIn[0]) ) zIn++;
1854+
while( isspace((unsigned char)zIn[0]) ) zIn++;
18551855
zOut = sqlite3_mprintf("%s", zIn);
18561856
if( zOut==0 ) return 0;
18571857
i = (int)strlen(zOut);

mptest/mptest.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
#include <assert.h>
4747
#include <ctype.h>
4848

49+
#define ISSPACE(X) isspace((unsigned char)(X))
50+
#define ISDIGIT(X) isdigit((unsigned char)(X))
51+
4952
/* The suffix to append to the child command lines, if any */
5053
#if defined(_WIN32)
5154
# define GETPID (int)GetCurrentProcessId
@@ -187,10 +190,10 @@ int strglob(const char *zGlob, const char *z){
187190
}
188191
if( c2==0 || (seen ^ invert)==0 ) return 0;
189192
}else if( c=='#' ){
190-
if( (z[0]=='-' || z[0]=='+') && isdigit(z[1]) ) z++;
191-
if( !isdigit(z[0]) ) return 0;
193+
if( (z[0]=='-' || z[0]=='+') && ISDIGIT(z[1]) ) z++;
194+
if( !ISDIGIT(z[0]) ) return 0;
192195
z++;
193-
while( isdigit(z[0]) ){ z++; }
196+
while( ISDIGIT(z[0]) ){ z++; }
194197
}else{
195198
if( c!=(*(z++)) ) return 0;
196199
}
@@ -289,7 +292,7 @@ static void logMessage(const char *zFormat, ...){
289292
*/
290293
static int clipLength(const char *z){
291294
int n = (int)strlen(z);
292-
while( n>0 && isspace(z[n-1]) ){ n--; }
295+
while( n>0 && ISSPACE(z[n-1]) ){ n--; }
293296
return n;
294297
}
295298

@@ -444,7 +447,7 @@ static void stringAppendTerm(String *p, const char *z){
444447
stringAppend(p, "nil", 3);
445448
return;
446449
}
447-
for(i=0; z[i] && !isspace(z[i]); i++){}
450+
for(i=0; z[i] && !ISSPACE(z[i]); i++){}
448451
if( i>0 && z[i]==0 ){
449452
stringAppend(p, z, i);
450453
return;
@@ -699,7 +702,7 @@ static char *readFile(const char *zFilename){
699702
*/
700703
static int tokenLength(const char *z, int *pnLine){
701704
int n = 0;
702-
if( isspace(z[0]) || (z[0]=='/' && z[1]=='*') ){
705+
if( ISSPACE(z[0]) || (z[0]=='/' && z[1]=='*') ){
703706
int inC = 0;
704707
int c;
705708
if( z[0]=='/' ){
@@ -708,7 +711,7 @@ static int tokenLength(const char *z, int *pnLine){
708711
}
709712
while( (c = z[n++])!=0 ){
710713
if( c=='\n' ) (*pnLine)++;
711-
if( isspace(c) ) continue;
714+
if( ISSPACE(c) ) continue;
712715
if( inC && c=='*' && z[n]=='/' ){
713716
n++;
714717
inC = 0;
@@ -734,7 +737,7 @@ static int tokenLength(const char *z, int *pnLine){
734737
}
735738
}else{
736739
int c;
737-
for(n=1; (c = z[n])!=0 && !isspace(c) && c!='"' && c!='\'' && c!=';'; n++){}
740+
for(n=1; (c = z[n])!=0 && !ISSPACE(c) && c!='"' && c!='\'' && c!=';'; n++){}
738741
}
739742
return n;
740743
}
@@ -748,7 +751,7 @@ static int extractToken(const char *zIn, int nIn, char *zOut, int nOut){
748751
zOut[0] = 0;
749752
return 0;
750753
}
751-
for(i=0; i<nIn && i<nOut-1 && !isspace(zIn[i]); i++){ zOut[i] = zIn[i]; }
754+
for(i=0; i<nIn && i<nOut-1 && !ISSPACE(zIn[i]); i++){ zOut[i] = zIn[i]; }
752755
zOut[i] = 0;
753756
return i;
754757
}
@@ -758,7 +761,7 @@ static int extractToken(const char *zIn, int nIn, char *zOut, int nOut){
758761
*/
759762
static int findEnd(const char *z, int *pnLine){
760763
int n = 0;
761-
while( z[n] && (strncmp(z+n,"--end",5) || !isspace(z[n+5])) ){
764+
while( z[n] && (strncmp(z+n,"--end",5) || !ISSPACE(z[n+5])) ){
762765
n += tokenLength(z+n, pnLine);
763766
}
764767
return n;
@@ -773,12 +776,12 @@ static int findEndif(const char *z, int stopAtElse, int *pnLine){
773776
int n = 0;
774777
while( z[n] ){
775778
int len = tokenLength(z+n, pnLine);
776-
if( (strncmp(z+n,"--endif",7)==0 && isspace(z[n+7]))
777-
|| (stopAtElse && strncmp(z+n,"--else",6)==0 && isspace(z[n+6]))
779+
if( (strncmp(z+n,"--endif",7)==0 && ISSPACE(z[n+7]))
780+
|| (stopAtElse && strncmp(z+n,"--else",6)==0 && ISSPACE(z[n+6]))
778781
){
779782
return n+len;
780783
}
781-
if( strncmp(z+n,"--if",4)==0 && isspace(z[n+4]) ){
784+
if( strncmp(z+n,"--if",4)==0 && ISSPACE(z[n+4]) ){
782785
int skip = findEndif(z+n+len, 0, pnLine);
783786
n += skip + len;
784787
}else{
@@ -888,7 +891,7 @@ static void runScript(
888891
while( (c = zScript[ii])!=0 ){
889892
prevLine = lineno;
890893
len = tokenLength(zScript+ii, &lineno);
891-
if( isspace(c) || (c=='/' && zScript[ii+1]=='*') ){
894+
if( ISSPACE(c) || (c=='/' && zScript[ii+1]=='*') ){
892895
ii += len;
893896
continue;
894897
}
@@ -909,7 +912,7 @@ static void runScript(
909912
if( g.iTrace>=2 ) logMessage("%.*s", len, zScript+ii);
910913
n = extractToken(zScript+ii+2, len-2, zCmd, sizeof(zCmd));
911914
for(nArg=0; n<len-2 && nArg<MX_ARG; nArg++){
912-
while( n<len-2 && isspace(zScript[ii+2+n]) ){ n++; }
915+
while( n<len-2 && ISSPACE(zScript[ii+2+n]) ){ n++; }
913916
if( n>=len-2 ) break;
914917
n += extractToken(zScript+ii+2+n, len-2-n,
915918
azArg[nArg], sizeof(azArg[nArg]));
@@ -976,7 +979,7 @@ static void runScript(
976979
if( strcmp(zCmd, "match")==0 ){
977980
int jj;
978981
char *zAns = zScript+ii;
979-
for(jj=7; jj<len-1 && isspace(zAns[jj]); jj++){}
982+
for(jj=7; jj<len-1 && ISSPACE(zAns[jj]); jj++){}
980983
zAns += jj;
981984
if( len-jj-1!=sResult.n || strncmp(sResult.z, zAns, len-jj-1) ){
982985
errorMessage("line %d of %s:\nExpected [%.*s]\n Got [%s]",
@@ -998,7 +1001,7 @@ static void runScript(
9981001
char *zAns = zScript+ii;
9991002
char *zCopy;
10001003
int isGlob = (zCmd[0]=='g');
1001-
for(jj=9-3*isGlob; jj<len-1 && isspace(zAns[jj]); jj++){}
1004+
for(jj=9-3*isGlob; jj<len-1 && ISSPACE(zAns[jj]); jj++){}
10021005
zAns += jj;
10031006
zCopy = sqlite3_mprintf("%.*s", len-jj-1, zAns);
10041007
if( (sqlite3_strglob(zCopy, sResult.z)==0)^isGlob ){
@@ -1050,7 +1053,7 @@ static void runScript(
10501053
*/
10511054
if( strcmp(zCmd, "print")==0 ){
10521055
int jj;
1053-
for(jj=7; jj<len && isspace(zScript[ii+jj]); jj++){}
1056+
for(jj=7; jj<len && ISSPACE(zScript[ii+jj]); jj++){}
10541057
logMessage("%.*s", len-jj, zScript+ii+jj);
10551058
}else
10561059

@@ -1062,7 +1065,7 @@ static void runScript(
10621065
if( strcmp(zCmd, "if")==0 ){
10631066
int jj, rc;
10641067
sqlite3_stmt *pStmt;
1065-
for(jj=4; jj<len && isspace(zScript[ii+jj]); jj++){}
1068+
for(jj=4; jj<len && ISSPACE(zScript[ii+jj]); jj++){}
10661069
pStmt = prepareSql("SELECT %.*s", len-jj, zScript+ii+jj);
10671070
rc = sqlite3_step(pStmt);
10681071
if( rc!=SQLITE_ROW || sqlite3_column_int(pStmt, 0)==0 ){

test/fuzzcheck.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
#include <stdarg.h>
7171
#include <ctype.h>
7272
#include "sqlite3.h"
73+
#define ISSPACE(X) isspace((unsigned char)(X))
74+
#define ISDIGIT(X) isdigit((unsigned char)(X))
75+
7376

7477
#ifdef __unix__
7578
# include <signal.h>
@@ -633,9 +636,9 @@ static void runSql(sqlite3 *db, const char *zSql, unsigned runFlags){
633636
if( runFlags & SQL_TRACE ){
634637
const char *z = zSql;
635638
int n;
636-
while( z<zMore && isspace(z[0]) ) z++;
639+
while( z<zMore && ISSPACE(z[0]) ) z++;
637640
n = (int)(zMore - z);
638-
while( n>0 && isspace(z[n-1]) ) n--;
641+
while( n>0 && ISSPACE(z[n-1]) ) n--;
639642
if( n==0 ) break;
640643
if( pStmt==0 ){
641644
printf("TRACE: %.*s (error: %s)\n", n, z, sqlite3_errmsg(db));
@@ -757,7 +760,7 @@ static int integerValue(const char *zArg){
757760
zArg++;
758761
}
759762
}else{
760-
while( isdigit(zArg[0]) ){
763+
while( ISDIGIT(zArg[0]) ){
761764
v = v*10 + zArg[0] - '0';
762765
zArg++;
763766
}

test/speedtest1.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ static const char zHelp[] =
4747
#include <stdarg.h>
4848
#include <string.h>
4949
#include <ctype.h>
50+
#define ISSPACE(X) isspace((unsigned char)(X))
51+
#define ISDIGIT(X) isdigit((unsigned char)(X))
5052

5153
#if SQLITE_VERSION_NUMBER<3005000
5254
# define sqlite3_int64 sqlite_int64
@@ -315,7 +317,7 @@ void speedtest1_final(void){
315317
/* Print an SQL statement to standard output */
316318
static void printSql(const char *zSql){
317319
int n = (int)strlen(zSql);
318-
while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ){ n--; }
320+
while( n>0 && (zSql[n-1]==';' || ISSPACE(zSql[n-1])) ){ n--; }
319321
if( g.bExplain ) printf("EXPLAIN ");
320322
printf("%.*s;\n", n, zSql);
321323
if( g.bExplain
@@ -414,7 +416,7 @@ void speedtest1_run(void){
414416
/* The sqlite3_trace() callback function */
415417
static void traceCallback(void *NotUsed, const char *zSql){
416418
int n = (int)strlen(zSql);
417-
while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ) n--;
419+
while( n>0 && (zSql[n-1]==';' || ISSPACE(zSql[n-1])) ) n--;
418420
fprintf(stderr,"%.*s;\n", n, zSql);
419421
}
420422

test/wordcount.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#include <stdlib.h>
8181
#include <stdarg.h>
8282
#include "sqlite3.h"
83+
#define ISALPHA(X) isalpha((unsigned char)(X))
8384

8485
/* Return the current wall-clock time */
8586
static sqlite3_int64 realTime(void){
@@ -392,8 +393,8 @@ int main(int argc, char **argv){
392393
/* Process the input file */
393394
while( fgets(zInput, sizeof(zInput), in) ){
394395
for(i=0; zInput[i]; i++){
395-
if( !isalpha(zInput[i]) ) continue;
396-
for(j=i+1; isalpha(zInput[j]); j++){}
396+
if( !ISALPHA(zInput[i]) ) continue;
397+
for(j=i+1; ISALPHA(zInput[j]); j++){}
397398

398399
/* Found a new word at zInput[i] that is j-i bytes long.
399400
** Process it into the wordcount table. */

tool/fuzzershell.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include <stdarg.h>
6868
#include <ctype.h>
6969
#include "sqlite3.h"
70+
#define ISDIGIT(X) isdigit((unsigned char)(X))
7071

7172
/*
7273
** All global variables are gathered into the "g" singleton.
@@ -383,7 +384,7 @@ static int integerValue(const char *zArg){
383384
zArg++;
384385
}
385386
}else{
386-
while( isdigit(zArg[0]) ){
387+
while( ISDIGIT(zArg[0]) ){
387388
v = v*10 + zArg[0] - '0';
388389
zArg++;
389390
}

0 commit comments

Comments
 (0)