From aee73ed6be15b3a2da2017faa10f20bcf54adbf3 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Fri, 5 Jul 2024 11:55:20 +0200 Subject: HST-S: handle short reads... --- HST-S/host/app.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'HST-S') diff --git a/HST-S/host/app.c b/HST-S/host/app.c index 19091bb..2c4e6a5 100644 --- a/HST-S/host/app.c +++ b/HST-S/host/app.c @@ -55,10 +55,14 @@ static void read_input(T* A, const Params p) { sprintf(dctFileName, "%s", p.file_name); if((File = fopen(dctFileName, "rb")) != NULL) { for(unsigned int y = 0; y < p.input_size; y++) { - fread(&temp, sizeof(unsigned short), 1, File); - A[y] = (unsigned int)ByteSwap16(temp); - if(A[y] >= 4096) - A[y] = 4095; + if (fread(&temp, sizeof(unsigned short), 1, File) == 1) { + A[y] = (unsigned int)ByteSwap16(temp); + if(A[y] >= 4096) + A[y] = 4095; + } else { + //printf("out of bounds read at offset %d -- seeking back to 0\n", y); + rewind(File); + } } fclose(File); } else { -- cgit v1.2.3