From 8132a09e2136ca2fda3378ff8ea0d545ab82f94d Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Fri, 29 Oct 2021 09:29:23 -0700 Subject: [PATCH] Test for valid destination in uxnasm --- src/uxnasm.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/uxnasm.c b/src/uxnasm.c index 26dce46..a2eec4e 100644 --- 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; }