diff options
author | Birte Kristina Friesel <birte.friesel@uos.de> | 2024-07-05 11:55:20 +0200 |
---|---|---|
committer | Birte Kristina Friesel <birte.friesel@uos.de> | 2024-07-05 11:55:20 +0200 |
commit | aee73ed6be15b3a2da2017faa10f20bcf54adbf3 (patch) | |
tree | b2d4c0df79ae298ee9d185e8fb6383f510cab944 | |
parent | d9e1b49e1e70bbc70b24f24f54394766da22c0ee (diff) |
HST-S: handle short reads...
-rw-r--r-- | HST-S/host/app.c | 12 |
1 files changed, 8 insertions, 4 deletions
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 { |