summaryrefslogtreecommitdiff
path: root/src/lib/syntax.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/syntax.c')
-rw-r--r--src/lib/syntax.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/lib/syntax.c b/src/lib/syntax.c
index 75d6c14..ae52343 100644
--- a/src/lib/syntax.c
+++ b/src/lib/syntax.c
@@ -240,15 +240,17 @@ scan_string(struct aplwc *aplwc, struct string *text, int oneline)
struct token_list *tokens;
size_t n, i;
+ MEMPTRS(aplwc, 1);
+ MEMPTR(0, text);
+
+ tokens = NULL;
rc = check(text, &n);
- if(rc != APLWC_OK){
- aplwc->last_error = rc;
- return NULL;
- }
+ if(rc != APLWC_OK)
+ goto end;
tokens = memory_alloc_token_list(aplwc, n);
if(tokens == NULL)
- return NULL;
+ goto end;
tokens->text = text;
tokens->length = n;
scan(text, tokens);
@@ -258,11 +260,17 @@ scan_string(struct aplwc *aplwc, struct string *text, int oneline)
continue;
for(i++; i < n; i++){
- if(tokens->tokens[i].tag != TOKEN_TAG_NEWLINE)
- return NULL;
+ if(tokens->tokens[i].tag != TOKEN_TAG_NEWLINE){
+ rc = APLWC_INVALID_SYNTAX;
+ tokens = NULL;
+ goto end;
+ }
}
}
+end:
+ aplwc->last_error = rc;
+ MEMPTRS_EXIT(aplwc);
return tokens;
}