Fossil SCM

Use strncmp() in place of memcmp() in six more places where one of the strings can be shorter than the length compared: vfile.c, dispatch.c, th_main.c and timeline.c.

dmestas 2026-11-13 23:39 UTC small-fixes-2
Commit e170dd83e5d053eafea3969c4f30ea98dd9bca80ec0fb2efc7368f8b68d1b343
+1 -1
--- src/dispatch.c
+++ src/dispatch.c
@@ -1120,11 +1120,11 @@
11201120
blob_appendf(&buf, "boolean ");
11211121
}
11221122
blob_appendf(&buf,"setting");
11231123
zDesc = blob_str(&buf);
11241124
}
1125
- if( memcmp(aCommand[i].zName, "test", 4)==0 ) continue;
1125
+ if( strncmp(aCommand[i].zName, "test", 4)==0 ) continue;
11261126
if( occHelp[aCommand[i].iHelp] > 0 ){
11271127
int j;
11281128
for(j=0; j<occHelp[aCommand[i].iHelp]; j++){
11291129
unsigned int e = aCommand[bktHelp[aCommand[i].iHelp][j]].eCmdFlags;
11301130
if( e & CMDFLAG_1ST_TIER ){
11311131
--- src/dispatch.c
+++ src/dispatch.c
@@ -1120,11 +1120,11 @@
1120 blob_appendf(&buf, "boolean ");
1121 }
1122 blob_appendf(&buf,"setting");
1123 zDesc = blob_str(&buf);
1124 }
1125 if( memcmp(aCommand[i].zName, "test", 4)==0 ) continue;
1126 if( occHelp[aCommand[i].iHelp] > 0 ){
1127 int j;
1128 for(j=0; j<occHelp[aCommand[i].iHelp]; j++){
1129 unsigned int e = aCommand[bktHelp[aCommand[i].iHelp][j]].eCmdFlags;
1130 if( e & CMDFLAG_1ST_TIER ){
1131
--- src/dispatch.c
+++ src/dispatch.c
@@ -1120,11 +1120,11 @@
1120 blob_appendf(&buf, "boolean ");
1121 }
1122 blob_appendf(&buf,"setting");
1123 zDesc = blob_str(&buf);
1124 }
1125 if( strncmp(aCommand[i].zName, "test", 4)==0 ) continue;
1126 if( occHelp[aCommand[i].iHelp] > 0 ){
1127 int j;
1128 for(j=0; j<occHelp[aCommand[i].iHelp]; j++){
1129 unsigned int e = aCommand[bktHelp[aCommand[i].iHelp][j]].eCmdFlags;
1130 if( e & CMDFLAG_1ST_TIER ){
1131
+3 -3
--- src/th_main.c
+++ src/th_main.c
@@ -1605,11 +1605,11 @@
16051605
void *p,
16061606
int argc,
16071607
const char **argv,
16081608
int *argl
16091609
){
1610
- if( argc!=4 || memcmp(argv[1],"link",5)!=0 ){
1610
+ if( argc!=4 || strncmp(argv[1],"link",5)!=0 ){
16111611
return Th_WrongNumArgs(interp, "submenu link LABEL URL");
16121612
}
16131613
if( argl[2]==0 ){
16141614
Th_SetResult(interp, "link's LABEL is empty", -1);
16151615
return TH_ERROR;
@@ -2725,11 +2725,11 @@
27252725
/*
27262726
** Make sure that the TH1 script error was not caused by a "missing"
27272727
** command hook handler as that is not actually an error condition.
27282728
*/
27292729
nResult = TH1_LEN(nResult);
2730
- if( memcmp(zResult, NO_COMMAND_HOOK_ERROR, nResult)!=0 ){
2730
+ if( strncmp(zResult, NO_COMMAND_HOOK_ERROR, nResult)!=0 ){
27312731
sendError(0,zResult, nResult, 0);
27322732
}else{
27332733
/*
27342734
** There is no command hook handler "installed". This situation
27352735
** is NOT actually an error.
@@ -2813,11 +2813,11 @@
28132813
/*
28142814
** Make sure that the TH1 script error was not caused by a "missing"
28152815
** webpage hook handler as that is not actually an error condition.
28162816
*/
28172817
nResult = TH1_LEN(nResult);
2818
- if( memcmp(zResult, NO_WEBPAGE_HOOK_ERROR, nResult)!=0 ){
2818
+ if( strncmp(zResult, NO_WEBPAGE_HOOK_ERROR, nResult)!=0 ){
28192819
sendError(0,zResult, nResult, 1);
28202820
}else{
28212821
/*
28222822
** There is no webpage hook handler "installed". This situation
28232823
** is NOT actually an error.
28242824
--- src/th_main.c
+++ src/th_main.c
@@ -1605,11 +1605,11 @@
1605 void *p,
1606 int argc,
1607 const char **argv,
1608 int *argl
1609 ){
1610 if( argc!=4 || memcmp(argv[1],"link",5)!=0 ){
1611 return Th_WrongNumArgs(interp, "submenu link LABEL URL");
1612 }
1613 if( argl[2]==0 ){
1614 Th_SetResult(interp, "link's LABEL is empty", -1);
1615 return TH_ERROR;
@@ -2725,11 +2725,11 @@
2725 /*
2726 ** Make sure that the TH1 script error was not caused by a "missing"
2727 ** command hook handler as that is not actually an error condition.
2728 */
2729 nResult = TH1_LEN(nResult);
2730 if( memcmp(zResult, NO_COMMAND_HOOK_ERROR, nResult)!=0 ){
2731 sendError(0,zResult, nResult, 0);
2732 }else{
2733 /*
2734 ** There is no command hook handler "installed". This situation
2735 ** is NOT actually an error.
@@ -2813,11 +2813,11 @@
2813 /*
2814 ** Make sure that the TH1 script error was not caused by a "missing"
2815 ** webpage hook handler as that is not actually an error condition.
2816 */
2817 nResult = TH1_LEN(nResult);
2818 if( memcmp(zResult, NO_WEBPAGE_HOOK_ERROR, nResult)!=0 ){
2819 sendError(0,zResult, nResult, 1);
2820 }else{
2821 /*
2822 ** There is no webpage hook handler "installed". This situation
2823 ** is NOT actually an error.
2824
--- src/th_main.c
+++ src/th_main.c
@@ -1605,11 +1605,11 @@
1605 void *p,
1606 int argc,
1607 const char **argv,
1608 int *argl
1609 ){
1610 if( argc!=4 || strncmp(argv[1],"link",5)!=0 ){
1611 return Th_WrongNumArgs(interp, "submenu link LABEL URL");
1612 }
1613 if( argl[2]==0 ){
1614 Th_SetResult(interp, "link's LABEL is empty", -1);
1615 return TH_ERROR;
@@ -2725,11 +2725,11 @@
2725 /*
2726 ** Make sure that the TH1 script error was not caused by a "missing"
2727 ** command hook handler as that is not actually an error condition.
2728 */
2729 nResult = TH1_LEN(nResult);
2730 if( strncmp(zResult, NO_COMMAND_HOOK_ERROR, nResult)!=0 ){
2731 sendError(0,zResult, nResult, 0);
2732 }else{
2733 /*
2734 ** There is no command hook handler "installed". This situation
2735 ** is NOT actually an error.
@@ -2813,11 +2813,11 @@
2813 /*
2814 ** Make sure that the TH1 script error was not caused by a "missing"
2815 ** webpage hook handler as that is not actually an error condition.
2816 */
2817 nResult = TH1_LEN(nResult);
2818 if( strncmp(zResult, NO_WEBPAGE_HOOK_ERROR, nResult)!=0 ){
2819 sendError(0,zResult, nResult, 1);
2820 }else{
2821 /*
2822 ** There is no webpage hook handler "installed". This situation
2823 ** is NOT actually an error.
2824
+1 -1
--- src/timeline.c
+++ src/timeline.c
@@ -269,11 +269,11 @@
269269
const char *z = zTagList;
270270
Blob links;
271271
blob_zero(&links);
272272
while( z && z[0] ){
273273
for(i=0; z[i] && (z[i]!=',' || z[i+1]!=' '); i++){}
274
- if( zThisTag==0 || memcmp(z, zThisTag, i)!=0 || zThisTag[i]!=0 ){
274
+ if( zThisTag==0 || strncmp(z, zThisTag, i)!=0 || zThisTag[i]!=0 ){
275275
blob_appendf(&links,
276276
"%z%#h</a>%.2s",
277277
href("%R/timeline?r=%#t&c=%t",i,z,zDate), i,z, &z[i]
278278
);
279279
}else{
280280
--- src/timeline.c
+++ src/timeline.c
@@ -269,11 +269,11 @@
269 const char *z = zTagList;
270 Blob links;
271 blob_zero(&links);
272 while( z && z[0] ){
273 for(i=0; z[i] && (z[i]!=',' || z[i+1]!=' '); i++){}
274 if( zThisTag==0 || memcmp(z, zThisTag, i)!=0 || zThisTag[i]!=0 ){
275 blob_appendf(&links,
276 "%z%#h</a>%.2s",
277 href("%R/timeline?r=%#t&c=%t",i,z,zDate), i,z, &z[i]
278 );
279 }else{
280
--- src/timeline.c
+++ src/timeline.c
@@ -269,11 +269,11 @@
269 const char *z = zTagList;
270 Blob links;
271 blob_zero(&links);
272 while( z && z[0] ){
273 for(i=0; z[i] && (z[i]!=',' || z[i+1]!=' '); i++){}
274 if( zThisTag==0 || strncmp(z, zThisTag, i)!=0 || zThisTag[i]!=0 ){
275 blob_appendf(&links,
276 "%z%#h</a>%.2s",
277 href("%R/timeline?r=%#t&c=%t",i,z,zDate), i,z, &z[i]
278 );
279 }else{
280
+1 -1
--- src/vfile.c
+++ src/vfile.c
@@ -417,11 +417,11 @@
417417
return 1;
418418
}
419419
if( zName[0]!='-' ) continue;
420420
for(i=0; i<count(azTemp); i++){
421421
n = (int)strlen(azTemp[i]);
422
- if( memcmp(azTemp[i], zName+1, n) ) continue;
422
+ if( strncmp(azTemp[i], zName+1, n) ) continue;
423423
if( zName[n+1]==0 ) return 1;
424424
if( zName[n+1]=='-' ){
425425
for(j=n+2; zName[j] && fossil_isdigit(zName[j]); j++){}
426426
if( zName[j]==0 ) return 1;
427427
}
428428
--- src/vfile.c
+++ src/vfile.c
@@ -417,11 +417,11 @@
417 return 1;
418 }
419 if( zName[0]!='-' ) continue;
420 for(i=0; i<count(azTemp); i++){
421 n = (int)strlen(azTemp[i]);
422 if( memcmp(azTemp[i], zName+1, n) ) continue;
423 if( zName[n+1]==0 ) return 1;
424 if( zName[n+1]=='-' ){
425 for(j=n+2; zName[j] && fossil_isdigit(zName[j]); j++){}
426 if( zName[j]==0 ) return 1;
427 }
428
--- src/vfile.c
+++ src/vfile.c
@@ -417,11 +417,11 @@
417 return 1;
418 }
419 if( zName[0]!='-' ) continue;
420 for(i=0; i<count(azTemp); i++){
421 n = (int)strlen(azTemp[i]);
422 if( strncmp(azTemp[i], zName+1, n) ) continue;
423 if( zName[n+1]==0 ) return 1;
424 if( zName[n+1]=='-' ){
425 for(j=n+2; zName[j] && fossil_isdigit(zName[j]); j++){}
426 if( zName[j]==0 ) return 1;
427 }
428

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button