Skip to content

Commit

Permalink
fix '-Wformat-overflow=' compiler warnings (#2700)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilason committed Dec 24, 2022
1 parent 237814f commit 10bb1d2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
14 changes: 12 additions & 2 deletions db/drivers/dbf/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
/* add table to database */
int add_table(char *table, char *name)
{
int res;
size_t buf_s;

G_debug(2, "add_table(): table = %s name = %s", table, name);

if (db.atables == db.ntables) {
Expand All @@ -49,11 +52,18 @@ int add_table(char *table, char *name)

strcpy(db.tables[db.ntables].name, table);

buf_s = sizeof(db.tables[db.ntables].file);
#ifdef __MINGW32__
sprintf(db.tables[db.ntables].file, "%s\\%s", db.name, name);
res = snprintf(db.tables[db.ntables].file, buf_s, "%s\\%s", db.name, name);
#else
sprintf(db.tables[db.ntables].file, "%s/%s", db.name, name);
res = snprintf(db.tables[db.ntables].file, buf_s, "%s/%s", db.name, name);
#endif
if (res >= buf_s) {
db_d_append_error(_("Unable to add table %s to %s. "
"The file path is too long."),
name, db.name);
return DB_FAILED;
}

db.tables[db.ntables].alive = TRUE;
db.tables[db.ntables].described = FALSE;
Expand Down
2 changes: 0 additions & 2 deletions display/d.legend.vect/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ int main(int argc, char **argv)
if (opt_input->answer) {
sep = G_option_to_separator(opt_sep);
file_name = opt_input->answer;
if (!file_name)
G_fatal_error(_("Unable to open input file <%s>"), file_name);
}
else {
sep = "|";
Expand Down
12 changes: 9 additions & 3 deletions display/d.legend/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void draw(const char *map_name, int maptype, int color, int thin, int lines,
int x0, x1, y0, y1, xyTemp;
int SigDigits;
unsigned int MaxLabelLen;
char DispFormat[5]; /* %.Xf\0 */
char DispFormat[6]; /* %.Xf\0 */
double maxCat;
int horiz;
char *units_bottom;
Expand Down Expand Up @@ -280,8 +280,14 @@ void draw(const char *map_name, int maptype, int color, int thin, int lines,
if (horiz)
sprintf(DispFormat, "%%d");
else {
if (maxCat > 0.0)
sprintf(DispFormat, "%%%dd", (int)(log10(fabs(maxCat))) + 1);
if (maxCat > 0.0) {
size_t b_s = sizeof(DispFormat);
int log_maxCat = (int)(log10(fabs(maxCat))) + 1;
if (snprintf(DispFormat, b_s, "%%%dd", log_maxCat) >= b_s)
G_fatal_error(
_("Failed to create format string with maxCat=%f."),
maxCat);
}
else
sprintf(DispFormat, "%%2d");
}
Expand Down
2 changes: 1 addition & 1 deletion raster/r.out.pov/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ int main(int argc, char *argv[])

outfilename = parm.tga->answer;
if (outfilename == NULL)
G_fatal_error(_("Invalid output filename <%s>"), outfilename);
G_fatal_error(_("Invalid output filename"));

if (NULL == (outf = fopen(outfilename, "wb")))
G_fatal_error(_("Unable to open output file <%s>"), outfilename);
Expand Down
5 changes: 2 additions & 3 deletions raster/r.sim/simlib/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,8 @@ int input_data(void)
cchez = create_float_matrix(rows, cols, manin_val);
}
else {
G_fatal_error(_("Raster map <%s> not found, and manin_val undefined, "
"choose one to be allowed to process"),
manin);
G_fatal_error(_("Manning's n raster map not found and manin_val "
"undefined, choose one to be allowed to process"));
}

/* Rain: read rain map or use a single value for all cells */
Expand Down

0 comments on commit 10bb1d2

Please sign in to comment.