Skip to content

Weird string behaviour on MacOS (all string ptrs seem to refer to/modify the same char buffer) #6031

@DanVorobiev

Description

@DanVorobiev

Version: v3.7.0 (v3.6.1 shows same behavior for me)
Language: C++
MacOS Mojave 10.14.2
XCode 10.1 (tried all compiler options, C++11..17, Gnu11..17, same problem)

Steps to reproduce the behavior:

  1. Starting with trivial api.proto:
syntax = "proto3";
message RegisterRequest {
    string device_id = 1;
    string device_type = 2;
}
  1. Trivial main.cpp:
#include "api.pb.h"
#include <iostream>

int main(int argc, const char * argv[])
{
    RegisterRequest* Request = new RegisterRequest();
    Request->set_device_type("123");
    Request->set_device_id("456789");

    std::cout << "DeviceType:" << Request->device_type() << ", DeviceID:" << Request->device_id() << "\n";
    return 0;
}
  1. After compiling and linking against libprotobuf.a, I see same text for both string fields:
DeviceType:456789, DeviceID:456789

Adding more string fields to message reproduces the pattern, all string ptrs seem to point to the same char buffer.

My impression is that all setter-methods (tried every kind, including mutable and set_allocated) just modify the same static "default-value buffer" instead of allocating new values for each field.

Maybe I miss some preprocessor definitions necessary for MacOS?
(Win libraries work fine; I even managed to do Android/iOS builds without major problems; but currently out of clues for this MacOS behavior).

Please advise :)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions