Skip to content

Commit

Permalink
Fix format-security compiler warnings (#5774) (#5781)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Chirico <[email protected]>
  • Loading branch information
jangorecki and MichaelChirico authored Dec 2, 2023
1 parent 67fb763 commit a413d3c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values)
targetcol = VECTOR_ELT(dt,coln);
}
const char *ret = memrecycle(targetcol, rows, 0, targetlen, thisvalue, 0, -1, coln+1, CHAR(STRING_ELT(names, coln)));
if (ret) warning(ret);
if (ret) warning("%s", ret);
}

*_Last_updated = numToDo; // the updates have taken place with no error, so update .Last.updated now
Expand Down
2 changes: 1 addition & 1 deletion src/forder.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int *anso = NULL;
static bool notFirst=false;

static char msg[1001];
#define STOP(...) do {snprintf(msg, 1000, __VA_ARGS__); cleanup(); error(msg);} while(0) // http://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html#Swallowing-the-Semicolon
#define STOP(...) do {snprintf(msg, 1000, __VA_ARGS__); cleanup(); error("%s", msg);} while(0) // http://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html#Swallowing-the-Semicolon
// use STOP in this file (not error()) to ensure cleanup() is called first
// snprintf to msg first in case nrow (just as an example) is provided in the message because cleanup() sets nrow to 0
#undef warning
Expand Down
4 changes: 2 additions & 2 deletions src/fwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ void fwriteMain(fwriteMainArgs args)
}
if (f==-1) {
*ch = '\0';
DTPRINT(buff);
DTPRINT("%s", buff);
free(buff);
} else {
int ret1=0, ret2=0;
Expand Down Expand Up @@ -926,7 +926,7 @@ void fwriteMain(fwriteMainArgs args)
errno=0;
if (f==-1) {
*ch='\0'; // standard C string end marker so DTPRINT knows where to stop
DTPRINT(myBuff);
DTPRINT("%s", myBuff);
} else if ((args.is_gzip ? WRITE(f, myzBuff, (int)myzbuffUsed)
: WRITE(f, myBuff, (int)(ch-myBuff))) == -1) {
failed=true; // # nocov
Expand Down
8 changes: 4 additions & 4 deletions src/rbindlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg)
const char *str = isString(s) ? CHAR(STRING_ELT(s,w2)) : "";
snprintf(buff, 1000, _("Column %d ['%s'] of item %d is missing in item %d. Use fill=TRUE to fill with NA (NULL for list columns), or use.names=FALSE to ignore column names.%s"),
w2+1, str, i+1, missi+1, extra );
if (usenames==TRUE) error(buff);
if (usenames==TRUE) error("%s", buff);
i = LENGTH(l); // break from outer i loop
break; // break from inner j loop
}
Expand All @@ -229,8 +229,8 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg)
}
const char *o = isNull(opt) ? "message" : CHAR(STRING_ELT(opt,0));
if (strcmp(o,"message")==0) { eval(PROTECT(lang2(install("message"),PROTECT(ScalarString(mkChar(buff))))), R_GlobalEnv); UNPROTECT(2); }
else if (strcmp(o,"warning")==0) warning(buff);
else if (strcmp(o,"error")==0) error(buff);
else if (strcmp(o,"warning")==0) warning("%s", buff);
else if (strcmp(o,"error")==0) error("%s", buff);
else if (strcmp(o,"none")!=0) warning(_("options()$datatable.rbindlist.check=='%s' which is not 'message'|'warning'|'error'|'none'. See news item 5 in v1.12.2."), o);
}
}
Expand Down Expand Up @@ -490,7 +490,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg)
}
for (int k=0; k<nLevel; ++k) SET_TRUELENGTH(levelsRaw[k], 0);
savetl_end();
if (warnStr[0]) warning(warnStr); // now savetl_end() has happened it's safe to call warning (could error if options(warn=2))
if (warnStr[0]) warning("%s", warnStr); // now savetl_end() has happened it's safe to call warning (could error if options(warn=2))
SEXP levelsSxp;
setAttrib(target, R_LevelsSymbol, levelsSxp=allocVector(STRSXP, nLevel));
for (int k=0; k<nLevel; ++k) SET_STRING_ELT(levelsSxp, k, levelsRaw[k]);
Expand Down
2 changes: 1 addition & 1 deletion src/subset.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ SEXP subsetDT(SEXP x, SEXP rows, SEXP cols) { // API change needs update NEWS.md
SEXP max = PROTECT(ScalarInteger(nrow)); nprotect++;
rows = PROTECT(convertNegAndZeroIdx(rows, max, ScalarLogical(TRUE), ScalarLogical(TRUE))); nprotect++;
const char *err = check_idx(rows, nrow, &anyNA, &orderedSubset);
if (err!=NULL) error(err);
if (err!=NULL) error("%s", err);
}

if (!isInteger(cols)) error(_("Internal error. Argument '%s' to %s is type '%s' not '%s'"), "cols", "Csubset", type2char(TYPEOF(cols)), "integer"); // # nocov
Expand Down

0 comments on commit a413d3c

Please sign in to comment.