Fossil SCM

Replaced a few sprintf() calls with sqlite3_snprintf() to squish warnings from Clang on macOS when configured with extra debugging. (These warnings don't normally appear.) There is one left in extsrc/shell.c which needs fixing upstream.

wyoung 2023-10-23 01:17 trunk
Commit dfa41afeab1581794389d0516688169081b53937f53541b85467efe9e65b82ad
2 files changed +3 -3 +1 -1
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -402,11 +402,11 @@
402402
char pos[32];
403403
memset(pos,0,32);
404404
assert( locus > 0 );
405405
/* expect BUGs if the following yields compiler warnings */
406406
if( iMark > 0 ){ /* a regular reference to a footnote */
407
- sprintf(pos, "%s-%d-%s", ctx->unique.c, iMark, l.c);
407
+ sqlite3_snprintf(sizeof(pos), pos, "%s-%d-%s", ctx->unique.c, iMark, l.c);
408408
if(span && blob_size(span)) {
409409
blob_append_literal(ob,"<span class='");
410410
append_footnote_upc(ob, upc, 0);
411411
blob_append_literal(ob,"notescope' id='noteref");
412412
blob_appendf(ob,"%s'>",pos);
@@ -425,11 +425,11 @@
425425
pos, pos, iMark);
426426
}
427427
}else{ /* misreference */
428428
assert( iMark == -1 );
429429
430
- sprintf(pos, "%s-%s", ctx->unique.c, l.c);
430
+ sqlite3_snprintf(sizeof(pos), pos, "%s-%s", ctx->unique.c, l.c);
431431
if(span && blob_size(span)) {
432432
blob_appendf(ob, "<span class='notescope' id='misref%s'>", pos);
433433
blob_appendb(ob, span);
434434
blob_trim(ob);
435435
blob_append_literal(ob, "<sup class='noteref misref'><a href='");
@@ -485,11 +485,11 @@
485485
/* make.footnote_item() invocations should pass args accordingly */
486486
const struct Blob *upc = text+1;
487487
assert( text );
488488
/* allow blob_size(text)==0 for constructs like [...](^ [] ()) */
489489
memset(pos,0,24);
490
- sprintf(pos, "%s-%d", unique, iMark);
490
+ sqlite3_snprintf(sizeof(pos), pos, "%s-%d", unique, iMark);
491491
blob_appendf(ob, "<li id='footnote%s' class='", pos);
492492
if( nUsed ){
493493
if( blob_size(text)>=_jfi_sz &&
494494
!memcmp(blob_buffer(text),_joined_footnote_indicator,_jfi_sz)){
495495
bJoin = 1;
496496
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -402,11 +402,11 @@
402 char pos[32];
403 memset(pos,0,32);
404 assert( locus > 0 );
405 /* expect BUGs if the following yields compiler warnings */
406 if( iMark > 0 ){ /* a regular reference to a footnote */
407 sprintf(pos, "%s-%d-%s", ctx->unique.c, iMark, l.c);
408 if(span && blob_size(span)) {
409 blob_append_literal(ob,"<span class='");
410 append_footnote_upc(ob, upc, 0);
411 blob_append_literal(ob,"notescope' id='noteref");
412 blob_appendf(ob,"%s'>",pos);
@@ -425,11 +425,11 @@
425 pos, pos, iMark);
426 }
427 }else{ /* misreference */
428 assert( iMark == -1 );
429
430 sprintf(pos, "%s-%s", ctx->unique.c, l.c);
431 if(span && blob_size(span)) {
432 blob_appendf(ob, "<span class='notescope' id='misref%s'>", pos);
433 blob_appendb(ob, span);
434 blob_trim(ob);
435 blob_append_literal(ob, "<sup class='noteref misref'><a href='");
@@ -485,11 +485,11 @@
485 /* make.footnote_item() invocations should pass args accordingly */
486 const struct Blob *upc = text+1;
487 assert( text );
488 /* allow blob_size(text)==0 for constructs like [...](^ [] ()) */
489 memset(pos,0,24);
490 sprintf(pos, "%s-%d", unique, iMark);
491 blob_appendf(ob, "<li id='footnote%s' class='", pos);
492 if( nUsed ){
493 if( blob_size(text)>=_jfi_sz &&
494 !memcmp(blob_buffer(text),_joined_footnote_indicator,_jfi_sz)){
495 bJoin = 1;
496
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -402,11 +402,11 @@
402 char pos[32];
403 memset(pos,0,32);
404 assert( locus > 0 );
405 /* expect BUGs if the following yields compiler warnings */
406 if( iMark > 0 ){ /* a regular reference to a footnote */
407 sqlite3_snprintf(sizeof(pos), pos, "%s-%d-%s", ctx->unique.c, iMark, l.c);
408 if(span && blob_size(span)) {
409 blob_append_literal(ob,"<span class='");
410 append_footnote_upc(ob, upc, 0);
411 blob_append_literal(ob,"notescope' id='noteref");
412 blob_appendf(ob,"%s'>",pos);
@@ -425,11 +425,11 @@
425 pos, pos, iMark);
426 }
427 }else{ /* misreference */
428 assert( iMark == -1 );
429
430 sqlite3_snprintf(sizeof(pos), pos, "%s-%s", ctx->unique.c, l.c);
431 if(span && blob_size(span)) {
432 blob_appendf(ob, "<span class='notescope' id='misref%s'>", pos);
433 blob_appendb(ob, span);
434 blob_trim(ob);
435 blob_append_literal(ob, "<sup class='noteref misref'><a href='");
@@ -485,11 +485,11 @@
485 /* make.footnote_item() invocations should pass args accordingly */
486 const struct Blob *upc = text+1;
487 assert( text );
488 /* allow blob_size(text)==0 for constructs like [...](^ [] ()) */
489 memset(pos,0,24);
490 sqlite3_snprintf(sizeof(pos), pos, "%s-%d", unique, iMark);
491 blob_appendf(ob, "<li id='footnote%s' class='", pos);
492 if( nUsed ){
493 if( blob_size(text)>=_jfi_sz &&
494 !memcmp(blob_buffer(text),_joined_footnote_indicator,_jfi_sz)){
495 bJoin = 1;
496
+1 -1
--- src/style.c
+++ src/style.c
@@ -795,11 +795,11 @@
795795
}
796796
Th_MaybeStore("current_feature", feature_from_page_path(local_zCurrentPage) );
797797
if( g.ftntsIssues[0] || g.ftntsIssues[1] ||
798798
g.ftntsIssues[2] || g.ftntsIssues[3] ){
799799
char buf[80];
800
- sprintf(&buf[0],"%i %i %i %i",g.ftntsIssues[0],g.ftntsIssues[1],
800
+ sqlite3_snprintf(sizeof(buf),buf,"%i %i %i %i",g.ftntsIssues[0],g.ftntsIssues[1],
801801
g.ftntsIssues[2],g.ftntsIssues[3]);
802802
Th_Store("footnotes_issues_counters", buf);
803803
}
804804
}
805805
806806
--- src/style.c
+++ src/style.c
@@ -795,11 +795,11 @@
795 }
796 Th_MaybeStore("current_feature", feature_from_page_path(local_zCurrentPage) );
797 if( g.ftntsIssues[0] || g.ftntsIssues[1] ||
798 g.ftntsIssues[2] || g.ftntsIssues[3] ){
799 char buf[80];
800 sprintf(&buf[0],"%i %i %i %i",g.ftntsIssues[0],g.ftntsIssues[1],
801 g.ftntsIssues[2],g.ftntsIssues[3]);
802 Th_Store("footnotes_issues_counters", buf);
803 }
804 }
805
806
--- src/style.c
+++ src/style.c
@@ -795,11 +795,11 @@
795 }
796 Th_MaybeStore("current_feature", feature_from_page_path(local_zCurrentPage) );
797 if( g.ftntsIssues[0] || g.ftntsIssues[1] ||
798 g.ftntsIssues[2] || g.ftntsIssues[3] ){
799 char buf[80];
800 sqlite3_snprintf(sizeof(buf),buf,"%i %i %i %i",g.ftntsIssues[0],g.ftntsIssues[1],
801 g.ftntsIssues[2],g.ftntsIssues[3]);
802 Th_Store("footnotes_issues_counters", buf);
803 }
804 }
805
806

Keyboard Shortcuts

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