Skip to content

Commit

Permalink
fix integer overflows in r.cost and r.walk (#2842)
Browse files Browse the repository at this point in the history
  • Loading branch information
metzm committed Feb 20, 2023
1 parent fc90bec commit b06c460
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion raster/r.cost/flag.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ FLAG *flag_create(int nrows, int ncols)
if (!new_flag->array)
G_fatal_error(_("Out of memory!"));

temp = (unsigned char *)G_malloc(nrows * new_flag->leng *
temp = (unsigned char *)G_malloc((size_t)nrows * new_flag->leng *
sizeof(unsigned char));

if (!temp)
Expand Down
4 changes: 2 additions & 2 deletions raster/r.cost/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ int main(int argc, char *argv[])
costs.cost_out = dnullval;
costs.nearest = 0;

total_cells = nrows * ncols;
total_cells = (long)nrows * ncols;

skip_nulls = Rast_is_d_null_value(&null_cost);

Expand Down Expand Up @@ -815,7 +815,7 @@ int main(int argc, char *argv[])
*/

G_debug(1, "total cells: %ld", total_cells);
G_debug(1, "nrows x ncols: %d", nrows * ncols);
G_debug(1, "nrows x ncols: %ld", (long)nrows * ncols);
G_message(_("Finding cost path..."));
n_processed = 0;
visited = flag_create(nrows, ncols);
Expand Down
2 changes: 1 addition & 1 deletion raster/r.walk/flag.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ FLAG *flag_create(int nrows, int ncols)
if (!new_flag->array)
G_fatal_error(_("Out of memory!"));

temp = (unsigned char *)G_malloc(nrows * new_flag->leng *
temp = (unsigned char *)G_malloc((size_t)nrows * new_flag->leng *
sizeof(unsigned char));

if (!temp)
Expand Down
4 changes: 2 additions & 2 deletions raster/r.walk/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ int main(int argc, char *argv[])
costs.cost_out = dnullval;
costs.nearest = 0;

total_cells = nrows * ncols;
total_cells = (long)nrows * ncols;

skip_nulls = Rast_is_d_null_value(&null_cost);

Expand Down Expand Up @@ -976,7 +976,7 @@ int main(int argc, char *argv[])
*/

G_debug(1, "total cells: %ld", total_cells);
G_debug(1, "nrows x ncols: %d", nrows * ncols);
G_debug(1, "nrows x ncols: %ld", (long)nrows * ncols);
G_message(_("Finding cost path..."));
n_processed = 0;
visited = flag_create(nrows, ncols);
Expand Down

0 comments on commit b06c460

Please sign in to comment.