diff --git a/build-cmake/CMakeLists.txt b/build-cmake/CMakeLists.txt index c71dd89..379dd1a 100644 --- a/build-cmake/CMakeLists.txt +++ b/build-cmake/CMakeLists.txt @@ -101,7 +101,7 @@ SET(CMAKE_CXX_STANDARD_REQUIRED ON) SET(CMAKE_CXX_EXTENSIONS OFF) ADD_CUSTOM_COMMAND(OUTPUT protobuf-c/protobuf-c.pb.cc protobuf-c/protobuf-c.pb.h COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} - ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I${MAIN_DIR} ${MAIN_DIR}/protobuf-c/protobuf-c.proto) + ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I${PROTOBUF_INCLUDE_DIR} -I${MAIN_DIR} ${MAIN_DIR}/protobuf-c/protobuf-c.proto) FILE(GLOB PROTOC_GEN_C_SRC ${MAIN_DIR}/protoc-c/*.h ${MAIN_DIR}/protoc-c/*.cc ) ADD_EXECUTABLE(protoc-gen-c ${PROTOC_GEN_C_SRC} protobuf-c/protobuf-c.pb.cc protobuf-c/protobuf-c.pb.h) target_include_directories(protoc-gen-c diff --git a/protobuf-c/protobuf-c.c b/protobuf-c/protobuf-c.c index 3d676a2..4b8b3f2 100644 --- a/protobuf-c/protobuf-c.c +++ b/protobuf-c/protobuf-c.c @@ -1888,7 +1888,6 @@ pack_buffer_packed_payload(const ProtobufCFieldDescriptor *field, for (i = 0; i < count; i++) { unsigned len = boolean_pack(((protobuf_c_boolean *) array)[i], scratch); buffer->append(buffer, len, scratch); - rv += len; } return count; default: @@ -2557,7 +2556,7 @@ parse_required_member(ScannedMember *scanned_member, if (maybe_clear && *pstr != NULL) { const char *def = scanned_member->field->default_value; - if (*pstr != NULL && *pstr != def) + if (*pstr != def) do_free(allocator, *pstr); } *pstr = do_alloc(allocator, len - pref_len + 1); diff --git a/protoc-c/c_field.cc b/protoc-c/c_field.cc index 0716744..d49c001 100644 --- a/protoc-c/c_field.cc +++ b/protoc-c/c_field.cc @@ -159,6 +159,11 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, if (oneof != NULL) variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_ONEOF"; + // Eliminate codesmell "or with 0" + if (variables["flags"].find("0 | ") == 0) { + variables["flags"].erase(0, 4); + } + printer->Print("{\n"); if (descriptor_->file()->options().has_optimize_for() && descriptor_->file()->options().optimize_for() == diff --git a/protoc-c/c_helpers.cc b/protoc-c/c_helpers.cc index 6fd0cd3..7ae356d 100644 --- a/protoc-c/c_helpers.cc +++ b/protoc-c/c_helpers.cc @@ -234,7 +234,7 @@ void PrintComment (io::Printer* printer, std::string comment) std::vector comment_lines; SplitStringUsing (comment, "\r\n", &comment_lines); printer->Print ("/*\n"); - for (int i = 0; i < comment_lines.size(); i++) + for (size_t i = 0; i < comment_lines.size(); i++) { if (!comment_lines[i].empty()) { @@ -286,7 +286,7 @@ const char* const kKeywordList[] = { std::set MakeKeywordsMap() { std::set result; - for (int i = 0; i < GOOGLE_ARRAYSIZE(kKeywordList); i++) { + for (size_t i = 0; i < GOOGLE_ARRAYSIZE(kKeywordList); i++) { result.insert(kKeywordList[i]); } return result; @@ -526,7 +526,7 @@ static int CEscapeInternal(const char* src, int src_len, char* dest, if (!isprint(*src) || (last_hex_escape && isxdigit(*src))) { if (dest_len - used < 4) // need space for 4 letter escape return -1; - sprintf(dest + used, (use_hex ? "\\x%02x" : "\\%03o"), + snprintf(dest + used, dest_len - used, (use_hex ? "\\x%02x" : "\\%03o"), static_cast(*src)); is_hex_escape = use_hex; used += 4; diff --git a/protoc-c/main.cc b/protoc-c/main.cc index 93c42d0..2095a49 100644 --- a/protoc-c/main.cc +++ b/protoc-c/main.cc @@ -9,9 +9,9 @@ int main(int argc, char* argv[]) { std::string invocation_name = argv[0]; std::string invocation_basename = invocation_name.substr(invocation_name.find_last_of("/") + 1); - const std::string legacy_name = "protoc-c"; + const std::string standalone_name = "protoc-c"; - if (invocation_basename == legacy_name) { + if (invocation_basename == standalone_name) { google::protobuf::compiler::CommandLineInterface cli; cli.RegisterGenerator("--c_out", &c_generator, "Generate C/H files."); cli.SetVersionInfo(PACKAGE_STRING); diff --git a/t/generated-code2/test-generated-code2.c b/t/generated-code2/test-generated-code2.c index 15f5dc8..5198af6 100755 --- a/t/generated-code2/test-generated-code2.c +++ b/t/generated-code2/test-generated-code2.c @@ -2370,7 +2370,7 @@ static Test tests[] = }; #define n_tests (sizeof(tests)/sizeof(Test)) -int main () +int main(void) { unsigned i; for (i = 0; i < n_tests; i++) diff --git a/t/version/version.c b/t/version/version.c index 6ee3c41..9fec1ab 100644 --- a/t/version/version.c +++ b/t/version/version.c @@ -35,7 +35,7 @@ #include "protobuf-c.h" int -main(int argc, char **argv) +main(void) { printf("PACKAGE_VERSION = %s\n", PACKAGE_VERSION);