From d7a725d733fe47b15efa7d73b129d00294f7ab48 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Mon, 5 Aug 2024 15:56:10 -0400 Subject: [PATCH 1/7] check return value --- raster3d/r3.in.v5d/v5d.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/raster3d/r3.in.v5d/v5d.c b/raster3d/r3.in.v5d/v5d.c index 810238981bd..3893ee68930 100644 --- a/raster3d/r3.in.v5d/v5d.c +++ b/raster3d/r3.in.v5d/v5d.c @@ -1967,7 +1967,9 @@ int v5dReadCompressedGrid(v5dstruct *v, int time, int var, float *ga, float *gb, /* move to position in file */ pos = grid_position(v, time, var); - lseek(v->FileDesc, pos, SEEK_SET); + if (lseek(v->FileDesc, pos, SEEK_SET) == -1) { + printf("lseek failed.\n"); + } /* read ga, gb arrays */ read_float4_array(v->FileDesc, ga, v->Nl[var]); From cd6c8a683b936842696bc3ba13c005c4d89ea097 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Mon, 5 Aug 2024 17:10:00 -0400 Subject: [PATCH 2/7] Changed printf to Gfatal --- raster3d/r3.in.v5d/v5d.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/raster3d/r3.in.v5d/v5d.c b/raster3d/r3.in.v5d/v5d.c index 3893ee68930..8b5c66c429d 100644 --- a/raster3d/r3.in.v5d/v5d.c +++ b/raster3d/r3.in.v5d/v5d.c @@ -63,6 +63,7 @@ #include #include #include +#include #include "binio.h" #include "v5d.h" #include "vis5d.h" @@ -1968,7 +1969,7 @@ int v5dReadCompressedGrid(v5dstruct *v, int time, int var, float *ga, float *gb, /* move to position in file */ pos = grid_position(v, time, var); if (lseek(v->FileDesc, pos, SEEK_SET) == -1) { - printf("lseek failed.\n"); + G_fatal_error("Seek error: %s", strerror(errno)); } /* read ga, gb arrays */ From 66ec84209e73f210f8a602766f485a6608356703 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Thu, 19 Sep 2024 14:39:07 -0400 Subject: [PATCH 3/7] Requested changes --- raster3d/r3.in.v5d/v5d.c | 59 +++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/raster3d/r3.in.v5d/v5d.c b/raster3d/r3.in.v5d/v5d.c index 8b5c66c429d..6f8a5f4520e 100644 --- a/raster3d/r3.in.v5d/v5d.c +++ b/raster3d/r3.in.v5d/v5d.c @@ -63,7 +63,9 @@ #include #include #include +#include #include + #include "binio.h" #include "v5d.h" #include "vis5d.h" @@ -1234,7 +1236,10 @@ static int read_comp_header(int f, v5dstruct *v) unsigned int id; /* reset file position to start of file */ - lseek(f, 0, SEEK_SET); + if (lseek(f, 0, SEEK_SET) == -1) { + G_warning(_("Unable to seek: %s"), strerror(errno)); + return 0; + } /* read file ID */ read_int4(f, (int *)&id); @@ -1336,8 +1341,8 @@ static int read_comp_header(int f, v5dstruct *v) /* skip ahead by 'gridsize' bytes */ if (lseek(f, gridsize, SEEK_CUR) == -1) { - printf("Error: Unexpected end of file, "); - printf("file may be corrupted.\n"); + G_warning(_("Error: Unexpected end of file, ")); + G_warning(_("file may be corrupted.\n")); return 0; } min = -(125.0 + gb) / ga; @@ -1480,7 +1485,10 @@ static int read_comp_grid(v5dstruct *v, int time, int var, float *ga, float *gb, /* move to position in file */ pos = grid_position(v, time, var); - lseek(f, pos, SEEK_SET); + if (lseek(f, pos, SEEK_SET) == -1) { + G_warning(_("Unable to seek: %s"), strerror(errno)); + return 0; + } if (v->FileFormat == 0x80808083) { /* read McIDAS grid and file numbers */ @@ -1553,7 +1561,13 @@ static int read_comp_grid(v5dstruct *v, int time, int var, float *ga, float *gb, */ static int read_v5d_header(v5dstruct *v) { -#define SKIP(N) lseek(f, N, SEEK_CUR) +#define SKIP(N) \ + do { \ + if (lseek(f, N, SEEK_CUR) == -1) { \ + G_warning(_("Unable to seek: %s"), strerror(errno)); \ + return 0; \ + } \ + } while (0) int end_of_header = 0; unsigned int id; int idlen, var, numargs; @@ -1872,13 +1886,19 @@ static int read_v5d_header(v5dstruct *v) case TAG_END: /* end of header */ end_of_header = 1; - lseek(f, length, SEEK_CUR); + if (lseek(f, length, SEEK_CUR) == -1) { + G_warning(_("Unable to seek: %s"), strerror(errno)); + return 0; + } break; default: /* unknown tag, skip to next tag */ printf("Unknown tag: %d length=%d\n", tag, length); - lseek(f, length, SEEK_CUR); + if (lseek(f, length, SEEK_CUR) == -1) { + G_warning(_("Unable to seek: %s"), strerror(errno)); + return 0; + } break; } } @@ -1969,7 +1989,8 @@ int v5dReadCompressedGrid(v5dstruct *v, int time, int var, float *ga, float *gb, /* move to position in file */ pos = grid_position(v, time, var); if (lseek(v->FileDesc, pos, SEEK_SET) == -1) { - G_fatal_error("Seek error: %s", strerror(errno)); + G_warning(_("Unable to seek: %s"), strerror(errno)); + return 0; } /* read ga, gb arrays */ @@ -2122,7 +2143,10 @@ static int write_v5d_header(v5dstruct *v) } /* set file pointer to start of file */ - lseek(f, 0, SEEK_SET); + if (lseek(f, 0, SEEK_SET) == -1) { + G_warning(_("Unable to seek: %s"), strerror(errno)); + return 0; + } v->CurPos = 0; /* @@ -2226,7 +2250,10 @@ static int write_v5d_header(v5dstruct *v) /* We're writing to a brand new file. Reserve 10000 bytes */ /* for future header growth. */ WRITE_TAG(v, TAG_END, 10000); - lseek(f, 10000, SEEK_CUR); + if (lseek(f, 10000, SEEK_CUR) == -1) { + G_warning(_("Unable to seek: %s"), strerror(errno)); + return 0; + } /* Let file pointer indicate where first grid is stored */ v->FirstGridPos = ltell(f); @@ -2340,7 +2367,7 @@ int v5dWriteCompressedGrid(const v5dstruct *v, int time, int var, pos = grid_position(v, time, var); if (lseek(v->FileDesc, pos, SEEK_SET) < 0) { /* lseek failed, return error */ - printf("Error in v5dWrite[Compressed]Grid: seek failed, disk full?\n"); + G_warning(_("Error in v5dWrite[Compressed]Grid: seek failed, disk full?\n")); return 0; } @@ -2456,9 +2483,15 @@ int v5dCloseFile(v5dstruct *v) if (v->Mode == 'w') { /* rewrite header because writing grids updates the minval and */ /* maxval fields */ - lseek(v->FileDesc, 0, SEEK_SET); + if (lseek(v->FileDesc, 0, SEEK_SET) == -1) { + G_warning(_("Unable to seek: %s"), strerror(errno)); + return 0; + } status = write_v5d_header(v); - lseek(v->FileDesc, 0, SEEK_END); + if (lseek(v->FileDesc, 0, SEEK_SET) == -1) { + G_warning(_("Unable to seek: %s"), strerror(errno)); + return 0; + } close(v->FileDesc); } else if (v->Mode == 'r') { From 7461590ce0bfe57e6d0dc8c7ed3bc037f7c732a0 Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Thu, 19 Sep 2024 14:45:11 -0400 Subject: [PATCH 4/7] Requested changes --- raster3d/r3.in.v5d/v5d.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raster3d/r3.in.v5d/v5d.c b/raster3d/r3.in.v5d/v5d.c index f969ef5ae84..bbf504ed80f 100644 --- a/raster3d/r3.in.v5d/v5d.c +++ b/raster3d/r3.in.v5d/v5d.c @@ -2487,7 +2487,7 @@ int v5dCloseFile(v5dstruct *v) return 0; } status = write_v5d_header(v); - if (lseek(v->FileDesc, 0, SEEK_SET) == -1) { + if (lseek(v->FileDesc, 0, SEEK_END) == -1) { G_warning(_("Unable to seek: %s"), strerror(errno)); return 0; } From 594894ccab4674d71c0abdfdb1bdb93f9ac8c08a Mon Sep 17 00:00:00 2001 From: ShubhamDesai <42180509+ShubhamDesai@users.noreply.github.com> Date: Thu, 19 Sep 2024 15:07:22 -0400 Subject: [PATCH 5/7] Update raster3d/r3.in.v5d/v5d.c Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- raster3d/r3.in.v5d/v5d.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/raster3d/r3.in.v5d/v5d.c b/raster3d/r3.in.v5d/v5d.c index bbf504ed80f..e3e6bbc433a 100644 --- a/raster3d/r3.in.v5d/v5d.c +++ b/raster3d/r3.in.v5d/v5d.c @@ -2366,7 +2366,8 @@ int v5dWriteCompressedGrid(const v5dstruct *v, int time, int var, pos = grid_position(v, time, var); if (lseek(v->FileDesc, pos, SEEK_SET) < 0) { /* lseek failed, return error */ - G_warning(_("Error in v5dWrite[Compressed]Grid: seek failed, disk full?\n")); + G_warning( + _("Error in v5dWrite[Compressed]Grid: seek failed, disk full?\n")); return 0; } From 2f83e2049e9de63a6218a03fb107232bf77d070b Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Mon, 23 Sep 2024 14:05:05 -0400 Subject: [PATCH 6/7] Requested G_warning changes --- raster3d/r3.in.v5d/v5d.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/raster3d/r3.in.v5d/v5d.c b/raster3d/r3.in.v5d/v5d.c index bbf504ed80f..97a772c4b63 100644 --- a/raster3d/r3.in.v5d/v5d.c +++ b/raster3d/r3.in.v5d/v5d.c @@ -1340,8 +1340,8 @@ static int read_comp_header(int f, v5dstruct *v) /* skip ahead by 'gridsize' bytes */ if (lseek(f, gridsize, SEEK_CUR) == -1) { - G_warning(_("Error: Unexpected end of file, ")); - G_warning(_("file may be corrupted.\n")); + G_warning(_("Error: Unexpected end of file, file may be " + "corrupted.")); return 0; } min = -(125.0 + gb) / ga; @@ -2366,7 +2366,9 @@ int v5dWriteCompressedGrid(const v5dstruct *v, int time, int var, pos = grid_position(v, time, var); if (lseek(v->FileDesc, pos, SEEK_SET) < 0) { /* lseek failed, return error */ - G_warning(_("Error in v5dWrite[Compressed]Grid: seek failed, disk full?\n")); + G_warning( + _("Error in v5dWrite[Compressed]Grid: seek failed, disk full? %s"), + strerror(errno)); return 0; } From f8b3e8dceb56a19ef9d8a4d67cc677272c5538ec Mon Sep 17 00:00:00 2001 From: Shubham Vasudeo Desai Date: Wed, 25 Sep 2024 15:15:33 -0400 Subject: [PATCH 7/7] G_warning message modified --- raster3d/r3.in.v5d/v5d.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/raster3d/r3.in.v5d/v5d.c b/raster3d/r3.in.v5d/v5d.c index 97a772c4b63..54f75f2361a 100644 --- a/raster3d/r3.in.v5d/v5d.c +++ b/raster3d/r3.in.v5d/v5d.c @@ -2366,9 +2366,7 @@ int v5dWriteCompressedGrid(const v5dstruct *v, int time, int var, pos = grid_position(v, time, var); if (lseek(v->FileDesc, pos, SEEK_SET) < 0) { /* lseek failed, return error */ - G_warning( - _("Error in v5dWrite[Compressed]Grid: seek failed, disk full? %s"), - strerror(errno)); + G_warning(_("Unable to seek: %s"), strerror(errno)); return 0; }