THRIFT-1755 Comment parsing bug

Patch: Brian Brooks & Jens Geyer
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 @@
     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 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 @@
   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;
   }