From b068f3ad2ea7b01aa1eb63cb655c3357f856e85b Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Wed, 20 May 2015 13:08:12 +0100 Subject: [PATCH] Fixed '#27 re2c crashes reading files containing %{ %}' (patch by Rui) --- re2c/bootstrap/scanner.cc | 18 +++++++++++------- re2c/scanner.re | 16 ++++++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/re2c/bootstrap/scanner.cc b/re2c/bootstrap/scanner.cc index 8b97545a..08bf4a4d 100644 --- a/re2c/bootstrap/scanner.cc +++ b/re2c/bootstrap/scanner.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.14.1.dev on Fri Feb 27 23:44:24 2015*/ +/* Generated by re2c 0.14.3.dev on Wed May 20 12:51:33 2015 */ /* $Id$ */ #include #include @@ -106,7 +106,7 @@ echo: { if (!ignore_eoc && !DFlag) { - out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok) - 1); + out.write(tok, cursor - tok - 1); // -1 so we don't write out the \0 } if(cursor == eof) @@ -135,7 +135,7 @@ yy7: } else if (!DFlag) { - out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); + out.write(tok, cursor - tok); } tok = pos = cursor; cline++; @@ -256,7 +256,10 @@ yy32: } if (!DFlag) { - out.write((const char*)(tok), (const char*)(&cursor[-7]) - (const char*)(tok)); + const size_t lexeme_len = cursor[-1] == '{' + ? sizeof ("%{") - 1 + : sizeof ("/*!re2c") - 1; + out.write(tok, cursor - tok - lexeme_len); } tok = cursor; RETURN(Parse); @@ -287,7 +290,8 @@ yy34: } if (!DFlag) { - out.write((const char*)(tok), (const char*)(&cursor[-11]) - (const char*)(tok)); + const size_t lexeme_len = sizeof ("/*!use:re2c") - 1; + out.write(tok, cursor - tok - lexeme_len); } tok = cursor; RETURN(Reuse); @@ -428,7 +432,7 @@ yy85: } else if (!DFlag) { - out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); + out.write(tok, cursor - tok); } tok = pos = cursor; goto echo; @@ -451,7 +455,7 @@ yy87: } else if (!DFlag) { - out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); + out.write(tok, cursor - tok); } tok = pos = cursor; goto echo; diff --git a/re2c/scanner.re b/re2c/scanner.re index 3bcf10ab..c51fe5a5 100644 --- a/re2c/scanner.re +++ b/re2c/scanner.re @@ -76,7 +76,10 @@ echo: } if (!DFlag) { - out.write((const char*)(tok), (const char*)(&cursor[-7]) - (const char*)(tok)); + const size_t lexeme_len = cursor[-1] == '{' + ? sizeof ("%{") - 1 + : sizeof ("/*!re2c") - 1; + out.write(tok, cursor - tok - lexeme_len); } tok = cursor; RETURN(Parse); @@ -109,7 +112,8 @@ echo: } if (!DFlag) { - out.write((const char*)(tok), (const char*)(&cursor[-11]) - (const char*)(tok)); + const size_t lexeme_len = sizeof ("/*!use:re2c") - 1; + out.write(tok, cursor - tok - lexeme_len); } tok = cursor; RETURN(Reuse); @@ -169,7 +173,7 @@ echo: } else if (!DFlag) { - out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); + out.write(tok, cursor - tok); } tok = pos = cursor; goto echo; @@ -186,7 +190,7 @@ echo: } else if (!DFlag) { - out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); + out.write(tok, cursor - tok); } tok = pos = cursor; goto echo; @@ -202,7 +206,7 @@ echo: } else if (!DFlag) { - out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok)); + out.write(tok, cursor - tok); } tok = pos = cursor; cline++; @@ -211,7 +215,7 @@ echo: zero { if (!ignore_eoc && !DFlag) { - out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok) - 1); + out.write(tok, cursor - tok - 1); // -1 so we don't write out the \0 } if(cursor == eof) -- 2.40.0