From 638c54d4dbd02a413218ffaeda0175c459d46fef Mon Sep 17 00:00:00 2001 From: Robert Edmonds Date: Sat, 25 Feb 2017 15:39:44 -0500 Subject: [PATCH] GenerateStructDefinition(): Reset vars["opt_comma"] when processing multiple oneofs This commit fixes #251, which causes incorrect code to be generated when there are multiple oneofs in the same message. In #221, we added code to force int-sizing for oneof enums, but we only set vars["opt_comma"] initially, before entering the loop over the message's oneofs. This caused commas to be omitted when generating the enums for subsequent oneofs after the first oneof. This commit resets vars["opt_comma"] every time through the loop that generates the enum declarations for the message's oneofs. --- protoc-c/c_message.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/protoc-c/c_message.cc b/protoc-c/c_message.cc index 2eedf2f..4c27cd1 100755 --- a/protoc-c/c_message.cc +++ b/protoc-c/c_message.cc @@ -148,9 +148,10 @@ GenerateStructDefinition(io::Printer* printer) { } // Generate the case enums for unions - vars["opt_comma"] = ","; for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { const OneofDescriptor *oneof = descriptor_->oneof_decl(i); + vars["opt_comma"] = ","; + vars["oneofname"] = FullNameToUpper(oneof->name()); vars["foneofname"] = FullNameToC(oneof->full_name());