From: David Reiss Date: Fri, 18 Jan 2008 07:39:36 +0000 (+0000) Subject: Thrift: Change the way constants are initialized to avoid segfaults. X-Git-Tag: 0.2.0~1035 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=050f3200a2963d00212d4f4b62acfe428ad789a6;p=common%2Fthrift.git Thrift: Change the way constants are initialized to avoid segfaults. Reviewed By: mcslee Test Plan: Looked at the patch carefully. Other Notes: Patch submitted by Dave Simpson. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665437 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc index 7200b554..1b560bc8 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -286,17 +286,16 @@ void t_cpp_generator::print_const_value(ofstream& out, string name, t_type* type for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) { string key = render_const_value(out, name, ktype, v_iter->first); string val = render_const_value(out, name, vtype, v_iter->second); - indent(out) << name << "[" << key << "] = " << val << ";" << endl; + indent(out) << name << ".insert(std::make_pair(" << key << ", " << val << "));" << endl; } out << endl; } else if (type->is_list()) { t_type* etype = ((t_list*)type)->get_elem_type(); const vector& val = value->get_list(); vector::const_iterator v_iter; - int i = 0; for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) { string val = render_const_value(out, name, etype, *v_iter); - indent(out) << name << "[" << (i++) << "] = " << val << ";" << endl; + indent(out) << name << ".push_back(" << val << ");" << endl; } out << endl; } else if (type->is_set()) {