commit 8132a09e2136ca2fda3378ff8ea0d545ab82f94d
parent 035e0d8a3ac0544fa88882f174bb6907ad2a38bf
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Fri, 29 Oct 2021 09:29:23 -0700
Test for valid destination in uxnasm
Diffstat:
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/uxnasm.c b/src/uxnasm.c
@@ -412,15 +412,16 @@ cleanup(char *filename)
int
main(int argc, char *argv[])
{
- FILE *f;
+ FILE *src, *dst;
if(argc < 3)
return !error("usage", "input.tal output.rom");
- if(!(f = fopen(argv[1], "r")))
- return !error("Load", "Failed to open source.");
- if(!pass1(f) || !pass2(f))
+ if(!(src = fopen(argv[1], "r")))
+ return !error("Invalid Input", argv[1]);
+ if(!pass1(src) || !pass2(src))
return !error("Assembly", "Failed to assemble rom.");
- fwrite(p.data + TRIM, p.length - TRIM, 1, fopen(argv[2], "wb"));
- fclose(f);
+ if(!(dst = fopen(argv[2], "wb")))
+ return !error("Invalid Output", argv[2]);
+ fwrite(p.data + TRIM, p.length - TRIM, 1, dst);
cleanup(argv[2]);
return 0;
}