From 33e2c8174814db39fe86a3535832a676d774b620 Mon Sep 17 00:00:00 2001 From: axel Date: Sat, 10 Dec 2005 10:33:35 +1000 Subject: [PATCH] Make sure tokenizer never changes input string darcs-hash:20051210003335-ac50b-2d1b9125186b1d3f68138c2c49559d077fa5d326.gz --- tokenizer.c | 9 +++++++-- tokenizer.h | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tokenizer.c b/tokenizer.c index 5e0fa42c7..50b6b8aca 100644 --- a/tokenizer.c +++ b/tokenizer.c @@ -138,7 +138,7 @@ void tok_init( tokenizer *tok, const wchar_t *b, int flags ) } tok->has_next = (*b != L'\0'); - tok->orig_buff = tok->buff = /*wcsdup*/(b); + tok->orig_buff = tok->buff = (wchar_t *)(b); if( !tok->orig_buff ) { @@ -152,7 +152,11 @@ void tok_init( tokenizer *tok, const wchar_t *b, int flags ) if( l != 0 ) { if( tok->orig_buff[l-1] == L'\\' ) + { + tok->free_orig = 1; + tok->orig_buff = wcsdup( tok->orig_buff ); tok->orig_buff[l-1] = L'\0'; + } } } @@ -163,7 +167,8 @@ void tok_init( tokenizer *tok, const wchar_t *b, int flags ) void tok_destroy( tokenizer *tok ) { free( tok->last ); -// free( tok->orig_buff ); + if( tok->free_orig ) + free( tok->orig_buff ); } int tok_last_type( tokenizer *tok ) diff --git a/tokenizer.h b/tokenizer.h index a0b0109ec..2a0ad513f 100644 --- a/tokenizer.h +++ b/tokenizer.h @@ -69,6 +69,8 @@ typedef struct int accept_unfinished; /** Whether commants should be returned*/ int show_comments; + /** Flag set to true of the orig_buff points to an internal string that needs to be free()d when deallocating the tokenizer. */ + int free_orig; /** Type of last quote, can be either ' or ".*/ wchar_t last_quote; }