From a062278e5bfa31b268f735aaa3bd250a4ec96a02 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Wed, 2 Oct 2024 16:26:47 -0400 Subject: [PATCH 1/3] fix unchecked value --- raster/r.fill.dir/filldir.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/raster/r.fill.dir/filldir.c b/raster/r.fill.dir/filldir.c index 55380b7dfc5..91303f364f3 100644 --- a/raster/r.fill.dir/filldir.c +++ b/raster/r.fill.dir/filldir.c @@ -145,14 +145,24 @@ void filldir(int fe, int fd, int nl, struct band3 *bnd) CELL *dir; /* fill single-cell depressions, except on outer rows and columns */ - lseek(fe, 0, SEEK_SET); + if (lseek(fe, 0, SEEK_SET) == -1) { + G_warning(_("Unable to seek: %s"), strerror(errno)); + return 0; + } + advance_band3(fe, bnd); advance_band3(fe, bnd); for (i = 1; i < nl - 1; i += 1) { - lseek(fe, (off_t)(i + 1) * bnd->sz, SEEK_SET); + if (lseek(fe, (off_t)(i + 1) * bnd->sz, SEEK_SET) == -1) { + G_warning(_("Unable to seek: %s"), strerror(errno)); + return 0; + } advance_band3(fe, bnd); if (fill_row(nl, bnd->ns, bnd)) { - lseek(fe, (off_t)i * bnd->sz, SEEK_SET); + if (lseek(fe, (off_t)i * bnd->sz, SEEK_SET) == -1) { + G_warning(_("Unable to seek: %s"), strerror(errno)); + return 0; + } if (write(fe, bnd->b[1], bnd->sz) < 0) G_fatal_error(_("File writing error in %s() %d:%s"), __func__, errno, strerror(errno)); @@ -172,8 +182,14 @@ void filldir(int fe, int fd, int nl, struct band3 *bnd) dir = G_calloc(bnd->ns, sizeof(CELL)); bufsz = bnd->ns * sizeof(CELL); - lseek(fe, 0, SEEK_SET); - lseek(fd, 0, SEEK_SET); + if (lseek(fe, 0, SEEK_SET) == -1) { + G_warning(_("Unable to seek: %s"), strerror(errno)); + return 0; + } + if (lseek(fd, 0, SEEK_SET) == -1) { + G_warning(_("Unable to seek: %s"), strerror(errno)); + return 0; + } advance_band3(fe, bnd); for (i = 0; i < nl; i += 1) { advance_band3(fe, bnd); From a68791662b49df99c2febff0a29024a4d48bb9d7 Mon Sep 17 00:00:00 2001 From: ShubhamDesai <42180509+ShubhamDesai@users.noreply.github.com> Date: Wed, 2 Oct 2024 16:30:31 -0400 Subject: [PATCH 2/3] Update raster/r.fill.dir/filldir.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- raster/r.fill.dir/filldir.c | 1 - 1 file changed, 1 deletion(-) diff --git a/raster/r.fill.dir/filldir.c b/raster/r.fill.dir/filldir.c index 91303f364f3..f7728ac3512 100644 --- a/raster/r.fill.dir/filldir.c +++ b/raster/r.fill.dir/filldir.c @@ -149,7 +149,6 @@ void filldir(int fe, int fd, int nl, struct band3 *bnd) G_warning(_("Unable to seek: %s"), strerror(errno)); return 0; } - advance_band3(fe, bnd); advance_band3(fe, bnd); for (i = 1; i < nl - 1; i += 1) { From 2e6e89530dacd9d6b3fd3a546965038d8483c74d Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Wed, 2 Oct 2024 16:41:31 -0400 Subject: [PATCH 3/3] G_fatal --- raster/r.fill.dir/filldir.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/raster/r.fill.dir/filldir.c b/raster/r.fill.dir/filldir.c index 91303f364f3..66d9bbc047a 100644 --- a/raster/r.fill.dir/filldir.c +++ b/raster/r.fill.dir/filldir.c @@ -146,22 +146,19 @@ void filldir(int fe, int fd, int nl, struct band3 *bnd) /* fill single-cell depressions, except on outer rows and columns */ if (lseek(fe, 0, SEEK_SET) == -1) { - G_warning(_("Unable to seek: %s"), strerror(errno)); - return 0; + G_fatal_error(_("Unable to seek: %s"), strerror(errno)); } advance_band3(fe, bnd); advance_band3(fe, bnd); for (i = 1; i < nl - 1; i += 1) { if (lseek(fe, (off_t)(i + 1) * bnd->sz, SEEK_SET) == -1) { - G_warning(_("Unable to seek: %s"), strerror(errno)); - return 0; + G_fatal_error(_("Unable to seek: %s"), strerror(errno)); } advance_band3(fe, bnd); if (fill_row(nl, bnd->ns, bnd)) { if (lseek(fe, (off_t)i * bnd->sz, SEEK_SET) == -1) { - G_warning(_("Unable to seek: %s"), strerror(errno)); - return 0; + G_fatal_error(_("Unable to seek: %s"), strerror(errno)); } if (write(fe, bnd->b[1], bnd->sz) < 0) G_fatal_error(_("File writing error in %s() %d:%s"), __func__, @@ -183,12 +180,10 @@ void filldir(int fe, int fd, int nl, struct band3 *bnd) bufsz = bnd->ns * sizeof(CELL); if (lseek(fe, 0, SEEK_SET) == -1) { - G_warning(_("Unable to seek: %s"), strerror(errno)); - return 0; + G_fatal_error(_("Unable to seek: %s"), strerror(errno)); } if (lseek(fd, 0, SEEK_SET) == -1) { - G_warning(_("Unable to seek: %s"), strerror(errno)); - return 0; + G_fatal_error(_("Unable to seek: %s"), strerror(errno)); } advance_band3(fe, bnd); for (i = 0; i < nl; i += 1) {