Skip to content

Commit 41fb35f

Browse files
committed
Add check for fread/fwrite result
1 parent d5514ac commit 41fb35f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/bin/pg_waldump/pg_waldump.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -883,30 +883,34 @@ static int32
883883
read_pq_int32(FILE* f)
884884
{
885885
int32 val;
886-
fread(&val, sizeof(val), 1, f);
886+
if (fread(&val, sizeof(val), 1, f) != 1)
887+
pg_fatal("could not read from file: %m");
887888
return pg_hton32(val);
888889
}
889890

890891
static int64
891892
read_pq_int64(FILE* f)
892893
{
893894
int64 val;
894-
fread(&val, sizeof(val), 1, f);
895+
if (fread(&val, sizeof(val), 1, f) != 1)
896+
pg_fatal("could not read from file: %m");
895897
return pg_hton64(val);
896898
}
897899

898900
static void
899901
write_pq_int32(FILE* f, int32 val)
900902
{
901903
val = pg_hton32(val);
902-
fwrite(&val, sizeof(val), 1, f);
904+
if (fwrite(&val, sizeof(val), 1, f) != 1)
905+
pg_fatal("could not write to file: %m");
903906
}
904907

905908
static void
906909
write_pq_int64(FILE* f, int64 val)
907910
{
908911
val = pg_hton64(val);
909-
fwrite(&val, sizeof(val), 1, f);
912+
if (fwrite(&val, sizeof(val), 1, f) != 1)
913+
pg_fatal("could not write to file: %m");
910914
}
911915

912916
static void

0 commit comments

Comments
 (0)