Updated Branches: refs/heads/master b2501a71a -> 8cd3efe50
THRIFT-1755 Comment parsing bug Patch: Brian Brooks & Jens Geyer Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/8cd3efe5 Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/8cd3efe5 Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/8cd3efe5 Branch: refs/heads/master Commit: 8cd3efe50a42975375e8ff3bc03306d9e4174314 Parents: b2501a7 Author: Jens Geyer <[email protected]> Authored: Mon Sep 16 22:17:52 2013 +0200 Committer: Jens Geyer <[email protected]> Committed: Mon Sep 16 22:17:52 2013 +0200 ---------------------------------------------------------------------- compiler/cpp/src/main.cc | 9 +++++++-- compiler/cpp/src/thriftl.ll | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/8cd3efe5/compiler/cpp/src/main.cc ---------------------------------------------------------------------- diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc index 0cefa7e..54c23f5 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; } http://git-wip-us.apache.org/repos/asf/thrift/blob/8cd3efe5/compiler/cpp/src/thriftl.ll ---------------------------------------------------------------------- diff --git a/compiler/cpp/src/thriftl.ll b/compiler/cpp/src/thriftl.ll index 8538652..96d61ec 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 <cassert> #include <string> #include <errno.h> #include <stdlib.h> @@ -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; }
