summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Geyer <jensg@apache.org>2015-09-25 20:52:57 +0200
committerJens Geyer <jensg@apache.org>2015-09-25 20:54:45 +0200
commit0621e1fc949a7e67c418b465f7f10ee082ea4a93 (patch)
treeb013878bce7c7ecf06f09359c3d91f637d652acc
parentc623197d37be470307c70c54d600ce8e74ed1373 (diff)
downloadthrift-0621e1fc949a7e67c418b465f7f10ee082ea4a93.tar.gz
THRIFT-3354 Fix word-extraction substr bug in initialism code
Client: Go Author: Prashant Varanasi <prashant@uber.com> This closes #625
-rw-r--r--compiler/cpp/src/generate/t_go_generator.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/cpp/src/generate/t_go_generator.cc b/compiler/cpp/src/generate/t_go_generator.cc
index 806614fbe..f04bc48ed 100644
--- a/compiler/cpp/src/generate/t_go_generator.cc
+++ b/compiler/cpp/src/generate/t_go_generator.cc
@@ -446,7 +446,11 @@ std::string t_go_generator::camelcase(const std::string& value) const {
// and if so replaces it with the upper case version of the word.
void t_go_generator::fix_common_initialism(std::string& value, int i) const {
if (!ignore_initialisms_) {
- std::string word = value.substr(i, value.find('_', i));
+ size_t wordLen = value.find('_', i);
+ if (wordLen != std::string::npos) {
+ wordLen -= i;
+ }
+ std::string word = value.substr(i, wordLen);
std::transform(word.begin(), word.end(), word.begin(), ::toupper);
if (commonInitialisms.find(word) != commonInitialisms.end()) {
value.replace(i, word.length(), word);