mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-16 19:15:10 +00:00
Saveguard against empty file
This commit is contained in:
parent
4713261184
commit
56131efa43
2 changed files with 6 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
|||
( init )
|
||||
|
||||
%emit ( byte -- ) { #18 DEO }
|
||||
%emit ( byte -- ) { ( macro comment ) #18 DEO }
|
||||
|
||||
|0100 @program
|
||||
|
||||
|
|
10
src/uxnasm.c
10
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);
|
||||
|
|
Loading…
Reference in a new issue