Merge pull request #675 from protobuf-c/edmonds/misc-fixes

Miscellaneous fixes
This commit is contained in:
Robert Edmonds 2023-07-08 22:40:07 -04:00 committed by GitHub
commit f46c1fd603
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 10 deletions

View File

@ -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

View File

@ -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);

View File

@ -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() ==

View File

@ -234,7 +234,7 @@ void PrintComment (io::Printer* printer, std::string comment)
std::vector<std::string> 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<std::string> MakeKeywordsMap() {
std::set<std::string> 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<uint8>(*src));
is_hex_escape = use_hex;
used += 4;

View File

@ -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);

View File

@ -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++)

View File

@ -35,7 +35,7 @@
#include "protobuf-c.h"
int
main(int argc, char **argv)
main(void)
{
printf("PACKAGE_VERSION = %s\n",
PACKAGE_VERSION);