aboutsummaryrefslogtreecommitdiff
path: root/objectivec/GPBMessage.m
diff options
context:
space:
mode:
authorThomas Van Lenten <thomasvl@google.com>2016-04-27 13:11:16 -0400
committerThomas Van Lenten <thomasvl@google.com>2016-04-27 13:57:11 -0400
commit30646288ad60fff7a3ce9c864a9bf481e6c4045a (patch)
tree0b190ec24c916307973072efd30bf99c0cfd2034 /objectivec/GPBMessage.m
parent66f074592dc343d6b4f7ad62fda5c26cccf6bf45 (diff)
downloadprotobuf-30646288ad60fff7a3ce9c864a9bf481e6c4045a.tar.gz
protobuf-30646288ad60fff7a3ce9c864a9bf481e6c4045a.tar.bz2
protobuf-30646288ad60fff7a3ce9c864a9bf481e6c4045a.zip
Fix up -hash/-isEqual: for bool storage.
Both methods weren't checking the has_bits (where the bools are stored), so it resulted in invalid results. Add a test that should shake out something like this in the future also.
Diffstat (limited to 'objectivec/GPBMessage.m')
-rw-r--r--objectivec/GPBMessage.m18
1 files changed, 13 insertions, 5 deletions
diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m
index 0e1599dc..8134e259 100644
--- a/objectivec/GPBMessage.m
+++ b/objectivec/GPBMessage.m
@@ -2603,9 +2603,13 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
size_t fieldOffset = field->description_->offset;
switch (fieldDataType) {
case GPBDataTypeBool: {
- BOOL *selfValPtr = (BOOL *)&selfStorage[fieldOffset];
- BOOL *otherValPtr = (BOOL *)&otherStorage[fieldOffset];
- if (*selfValPtr != *otherValPtr) {
+ // Bools are stored in has_bits to avoid needing explicit space in
+ // the storage structure.
+ // (the field number passed to the HasIvar helper doesn't really
+ // matter since the offset is never negative)
+ BOOL selfValue = GPBGetHasIvar(self, (int32_t)(fieldOffset), 0);
+ BOOL otherValue = GPBGetHasIvar(other, (int32_t)(fieldOffset), 0);
+ if (selfValue != otherValue) {
return NO;
}
break;
@@ -2714,8 +2718,12 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
size_t fieldOffset = field->description_->offset;
switch (fieldDataType) {
case GPBDataTypeBool: {
- BOOL *valPtr = (BOOL *)&storage[fieldOffset];
- result = prime * result + *valPtr;
+ // Bools are stored in has_bits to avoid needing explicit space in
+ // the storage structure.
+ // (the field number passed to the HasIvar helper doesn't really
+ // matter since the offset is never negative)
+ BOOL value = GPBGetHasIvar(self, (int32_t)(fieldOffset), 0);
+ result = prime * result + value;
break;
}
case GPBDataTypeSFixed32: