commit 56131efa432da92722949dfeefbb054f1ced900a
parent 471326118469f21009f8712d1849061120bba7b0
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Wed, 27 Mar 2024 12:11:51 -0700
Saveguard against empty file
Diffstat:
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/etc/hello.tal b/etc/hello.tal
@@ -1,6 +1,6 @@
( init )
-%emit ( byte -- ) { #18 DEO }
+%emit ( byte -- ) { ( macro comment ) #18 DEO }
|0100 @program
diff --git a/src/uxnasm.c b/src/uxnasm.c
@@ -104,7 +104,7 @@ walkcomment(FILE *f)
{
char c;
int depth = 1;
- while(fread(&c, 1, 1, f)) {
+ while(f && fread(&c, 1, 1, f)) {
if(c == 0xa) line++;
if(c == '(') depth++;
if(c == ')' && --depth < 1) return 1;
@@ -131,7 +131,7 @@ static int
walkfile(FILE *f)
{
char c, *cptr = token;
- while(fread(&c, 1, 1, f)) {
+ while(f && fread(&c, 1, 1, f)) {
if(c == 0xa) line++;
if(c < 0x21) {
*cptr++ = 0x00;
@@ -149,8 +149,8 @@ walkfile(FILE *f)
static int
makemacro(char *name, FILE *f)
{
- Item *m;
char c;
+ Item *m;
if(!slen(name)) return error_asm("Macro is empty");
if(findmacro(name)) return error_asm("Macro is duplicate");
if(sihx(name)) return error_asm("Macro is hex number");
@@ -159,9 +159,9 @@ makemacro(char *name, FILE *f)
m = ¯os[macro_len++];
m->name = push(name, 0);
m->content = dictnext;
- while(fread(&c, 1, 1, f) && c != '{')
+ while(f && fread(&c, 1, 1, f) && c != '{')
if(c == 0xa) line++;
- while(fread(&c, 1, 1, f) && c != '}') {
+ while(f && fread(&c, 1, 1, f) && c != '}') {
if(c == 0xa) line++;
if(c == '%') return 0;
if(c == '(') walkcomment(f);