shithub: rgbds

Download patch

ref: 0c71f5a4e91b92718f1c3bd94c43d7760ac89fd6
parent: 4b0dfd4f4add69a0c5f1b1984ae049ba8df2cc8d
author: Antonio Niño Díaz <[email protected]>
date: Mon Aug 21 19:35:52 EDT 2017

Check return values of fread in rgblink

Signed-off-by: Antonio Niño Díaz <[email protected]>

--- a/src/link/output.c
+++ b/src/link/output.c
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "extern/err.h"
 #include "link/mylink.h"
 #include "link/mapfile.h"
 #include "link/main.h"
@@ -24,7 +25,10 @@
 
 	if (f_overlay != NULL) {
 		fseek(f_overlay, 0L, SEEK_SET);
-		fread(mem, 1, MaxAvail[BANK_ROM0], f_overlay);
+		if (fread(mem, 1, MaxAvail[BANK_ROM0], f_overlay) !=
+		    MaxAvail[BANK_ROM0]) {
+			warnx("Failed to read data from overlay file.");
+		}
 	} else {
 		memset(mem, fillchar, MaxAvail[BANK_ROM0]);
 	}
@@ -58,7 +62,10 @@
 
 	if (f_overlay != NULL && bank <= MaxOverlayBank) {
 		fseek(f_overlay, bank*0x4000, SEEK_SET);
-		fread(mem, 1, MaxAvail[bank], f_overlay);
+		if (fread(mem, 1, MaxAvail[bank], f_overlay) !=
+		    MaxAvail[bank]) {
+			warnx("Failed to read data from overlay file.");
+		}
 	} else {
 		memset(mem, fillchar, MaxAvail[bank]);
 	}