diff --git a/db/drivers/dbf/table.c b/db/drivers/dbf/table.c index 9b829f22ddc..b827ccc7db7 100644 --- a/db/drivers/dbf/table.c +++ b/db/drivers/dbf/table.c @@ -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) { @@ -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; diff --git a/display/d.legend.vect/main.c b/display/d.legend.vect/main.c index f895664a85d..72989a23cb2 100644 --- a/display/d.legend.vect/main.c +++ b/display/d.legend.vect/main.c @@ -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 = "|"; diff --git a/display/d.legend/draw.c b/display/d.legend/draw.c index d1350490043..1e7c6807084 100644 --- a/display/d.legend/draw.c +++ b/display/d.legend/draw.c @@ -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; @@ -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"); } diff --git a/raster/r.out.pov/main.c b/raster/r.out.pov/main.c index e9bfe179881..ee601f97e05 100644 --- a/raster/r.out.pov/main.c +++ b/raster/r.out.pov/main.c @@ -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); diff --git a/raster/r.sim/simlib/input.c b/raster/r.sim/simlib/input.c index 535742ccd26..10a2a332f11 100644 --- a/raster/r.sim/simlib/input.c +++ b/raster/r.sim/simlib/input.c @@ -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 */