From 8cd3efe50a42975375e8ff3bc03306d9e4174314 Mon Sep 17 00:00:00 2001 From: Jens Geyer Date: Mon, 16 Sep 2013 22:17:52 +0200 Subject: [PATCH] THRIFT-1755 Comment parsing bug Patch: Brian Brooks & Jens Geyer --- compiler/cpp/src/main.cc | 9 +++++++-- compiler/cpp/src/thriftl.ll | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc index 0cefa7ec..54c23f5e 100755 --- a/compiler/cpp/src/main.cc +++ b/compiler/cpp/src/main.cc @@ -517,8 +517,13 @@ char* clean_up_doctext(char* doctext) { docstring += '\n'; } - assert(docstring.length() <= strlen(doctext)); - strcpy(doctext, docstring.c_str()); + //assert(docstring.length() <= strlen(doctext)); may happen, see THRIFT-1755 + if(docstring.length() <= strlen(doctext)) { + strcpy(doctext, docstring.c_str()); + } else { + free(doctext); // too short + doctext = strdup(docstring.c_str()); + } return doctext; } diff --git a/compiler/cpp/src/thriftl.ll b/compiler/cpp/src/thriftl.ll index 85386525..96d61ecf 100644 --- a/compiler/cpp/src/thriftl.ll +++ b/compiler/cpp/src/thriftl.ll @@ -36,6 +36,7 @@ #pragma GCC diagnostic ignored "-Wunused-function" #pragma GCC diagnostic ignored "-Wunused-label" +#include #include #include #include @@ -366,7 +367,9 @@ literal_begin (['\"]) if (g_parse_mode == PROGRAM) { clear_doctext(); g_doctext = strdup(yytext + 3); - g_doctext[strlen(g_doctext) - 2] = '\0'; + assert(strlen(g_doctext) >= 2); + g_doctext[strlen(g_doctext) - 2] = ' '; + g_doctext[strlen(g_doctext) - 1] = '\0'; g_doctext = clean_up_doctext(g_doctext); g_doctext_lineno = yylineno; } -- 2.17.1