load: don't leak file handles; don't ignore read errors

This commit is contained in:
Sigrid Solveig Haflínudóttir 2021-11-17 14:21:27 +01:00
parent 6c1720e328
commit 19c16081c6
No known key found for this signature in database
GPG Key ID: FC8DDA5A6A7456C4
1 changed files with 4 additions and 1 deletions

View File

@ -422,8 +422,11 @@ static int
load(Uxn *u, char *rom)
{
FILE *f;
int r;
if(!(f = fopen(rom, "rb"))) return 0;
fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f);
r = fread(u->ram.dat + PAGE_PROGRAM, 1, sizeof(u->ram.dat) - PAGE_PROGRAM, f);
fclose(f);
if(r < 1) return 0;
fprintf(stderr, "Loaded %s\n", rom);
SDL_SetWindowTitle(gWindow, rom);
return 1;