Test for valid destination in uxnasm

This commit is contained in:
Devine Lu Linvega 2021-10-29 09:29:23 -07:00
parent 035e0d8a3a
commit 8132a09e21
1 changed files with 7 additions and 6 deletions

View File

@ -412,15 +412,16 @@ cleanup(char *filename)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
FILE *f; FILE *src, *dst;
if(argc < 3) if(argc < 3)
return !error("usage", "input.tal output.rom"); return !error("usage", "input.tal output.rom");
if(!(f = fopen(argv[1], "r"))) if(!(src = fopen(argv[1], "r")))
return !error("Load", "Failed to open source."); return !error("Invalid Input", argv[1]);
if(!pass1(f) || !pass2(f)) if(!pass1(src) || !pass2(src))
return !error("Assembly", "Failed to assemble rom."); return !error("Assembly", "Failed to assemble rom.");
fwrite(p.data + TRIM, p.length - TRIM, 1, fopen(argv[2], "wb")); if(!(dst = fopen(argv[2], "wb")))
fclose(f); return !error("Invalid Output", argv[2]);
fwrite(p.data + TRIM, p.length - TRIM, 1, dst);
cleanup(argv[2]); cleanup(argv[2]);
return 0; return 0;
} }