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.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/lib/syntax.c b/src/lib/syntax.c
index 395c75e..ae52343 100644
--- a/src/lib/syntax.c
+++ b/src/lib/syntax.c
@@ -240,17 +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->memory, n);
- if(tokens == NULL){
- aplwc->last_error = APLWC_OUT_OF_MEMORY;
- return NULL;
- }
+ tokens = memory_alloc_token_list(aplwc, n);
+ if(tokens == NULL)
+ goto end;
tokens->text = text;
tokens->length = n;
scan(text, tokens);
@@ -261,12 +261,16 @@ scan_string(struct aplwc *aplwc, struct string *text, int oneline)
for(i++; i < n; i++){
if(tokens->tokens[i].tag != TOKEN_TAG_NEWLINE){
- memory_free_token_list(&aplwc->memory, tokens);
- return NULL;
+ rc = APLWC_INVALID_SYNTAX;
+ tokens = NULL;
+ goto end;
}
}
}
+end:
+ aplwc->last_error = rc;
+ MEMPTRS_EXIT(aplwc);
return tokens;
}