New issue 285 by co...@colinday.net: Generated C++ operator= to CopyFrom()
to MergeFrom() mishandles bytes fields as strings
http://code.google.com/p/protobuf/issues/detail?id=285
What steps will reproduce the problem?
1. Create a field of type 'bytes'
2. Assign it a value "\0\0\0\0abc"
3. Assign to make a copy
What is the expected output? What do you see instead?
I expect the data "\0\0\0\0abc" to be copied to the destination, but
instead the generated MergeFrom() function treats the field as type string
that copies no data because it's interpreted as an empty string due to the
leading zero using:
set_fieldname(from.fieldname().c_str());
What version of the product are you using? On what operating system?
Protocol Buffers v2.3.0, Windows 7, C++
Please provide any additional information below.
Comment #1 on issue 285 by jas...@google.com: Generated C++ operator= to
CopyFrom() to MergeFrom() mishandles bytes fields as strings
http://code.google.com/p/protobuf/issues/detail?id=285
Are you sure that when you execute step 2, the field actually gets that
string value assigned? Note that the setter accepts a const char*, so if
your code does:
foo.set_fieldname("\0\0\0\0abc")
You end up setting the source to a zero-length string. You would instead
need to do:
string value("\0\0\0\0abc", 7);
foo.set_fieldname(value);
When I set the field this way, the full field was properly copied. For
MergeFrom, the code generator emits:
set_fieldname(from.fieldname());
Looking through the revision history it does not appear to have ever used
c_str()