Skip to content

Commit

Permalink
r.clump: Fix unchecked return value from lseek (#4151)
Browse files Browse the repository at this point in the history
This change addresses an issue identified by Coverity Scan (CID : 1415709) [unchecked return value from library]. The checks are added for lseek usages using an error message already used in the library.

---------

Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com>
  • Loading branch information
ShubhamDesai and echoix authored Sep 16, 2024
1 parent d7c126f commit 7c27080
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions raster/r.clump/clump.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <grass/raster.h>
#include <grass/glocale.h>
#include "local_proto.h"
#include <errno.h>
#include <string.h>

#define INCR 1024

Expand Down Expand Up @@ -92,7 +94,9 @@ static CELL do_renumber(int *in_fd, DCELL *rng, int nin, int diag, int minsize,
G_percent(row, nrows, 2);

coffset = (off_t)row * csize;
lseek(cfd, coffset, SEEK_SET);
if (lseek(cfd, coffset, SEEK_SET) == -1) {
G_fatal_error(_("Unable to seek: %s"), strerror(errno));
}
if (read(cfd, cur_clump, csize) != csize)
G_fatal_error(_("Unable to read from temp file"));

Expand All @@ -108,7 +112,9 @@ static CELL do_renumber(int *in_fd, DCELL *rng, int nin, int diag, int minsize,
temp_clump++;
}
if (do_write) {
lseek(cfd, coffset, SEEK_SET);
if (lseek(cfd, coffset, SEEK_SET) == -1) {
G_fatal_error(_("Unable to seek: %s"), strerror(errno));
}
if (write(cfd, cur_clump, csize) != csize)
G_fatal_error(_("Unable to write to temp file"));
}
Expand Down

0 comments on commit 7c27080

Please sign in to comment.