bumpy-b / protobuf-embedded-c

Automatically exported from code.google.com/p/protobuf-embedded-c
0 stars 0 forks source link

Code generated for default value checks for optional string elements (bytes) is incorrect #47

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Define a message with like:
  message CipherKeys {
    required bytes localKey = 1;
    required uint32 localKeyChkSum = 2;
    optional bytes groupKey = 3;
    optional uint32 groupKeyChkSum = 4;
  }

2. Look at the code generated for CipherKeys_write().  The code should be 
checking for empty string.  Code generate looks like:

/* Write the optional attribute only if it is different than the default value. 
*/
if(_CipherKeys->_groupKey_len != 1
 || _CipherKeys->_groupKey[0] != '0') {
    offset = write_raw_varint32((3<<3)+2, _buffer, offset);
    offset = write_raw_varint32(_CipherKeys->_groupKey_len, _buffer, offset);
    offset = write_raw_bytes(_CipherKeys->_groupKey, _CipherKeys->_groupKey_len, _buffer, offset);
  }
The check for length should be _CipherKeys->_groupKey_len != 0 and the check 
for a null string should be _CipherKeys->_groupKey[0] != '\0'

What version of the product are you using? On what operating system?
1.04M, host Windows XP, target IAR 5.51 MSP430

Original issue reported on code.google.com by alan.joh...@gd-ais.com on 20 Aug 2013 at 1:35

GoogleCodeExporter commented 9 years ago
Note:  The message field for groupKey is "string" not "bytes" in the message 
definition.

Original comment by alan.joh...@gd-ais.com on 20 Aug 2013 at 9:18