Commit 20b4e84f authored by Thomas Van Lenten's avatar Thomas Van Lenten

Merge pull request #1020 from thomasvl/block_nil

Check and throw errors for nil values/keys (like NSDictionary).
parents 764a2248 c3a0cf74
...@@ -601,7 +601,7 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -601,7 +601,7 @@ void GPBDictionaryReadEntry(id mapDictionary,
//% _dictionary = [[NSMutableDictionary alloc] init]; //% _dictionary = [[NSMutableDictionary alloc] init];
//% if (count && VNAME##s && keys) { //% if (count && VNAME##s && keys) {
//% for (NSUInteger i = 0; i < count; ++i) { //% for (NSUInteger i = 0; i < count; ++i) {
//% [_dictionary setObject:WRAPPED##VHELPER(VNAME##s[i]) forKey:WRAPPED##KHELPER(keys[i])]; //%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME##s[i], ______)##DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELPER(VNAME##s[i]) forKey:WRAPPED##KHELPER(keys[i])];
//% } //% }
//% } //% }
//% } //% }
...@@ -711,7 +711,7 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -711,7 +711,7 @@ void GPBDictionaryReadEntry(id mapDictionary,
//% _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); //% _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
//% if (count && rawValues && keys) { //% if (count && rawValues && keys) {
//% for (NSUInteger i = 0; i < count; ++i) { //% for (NSUInteger i = 0; i < count; ++i) {
//% [_dictionary setObject:WRAPPED##VHELPER(rawValues[i]) forKey:WRAPPED##KHELPER(keys[i])]; //%DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELPER(rawValues[i]) forKey:WRAPPED##KHELPER(keys[i])];
//% } //% }
//% } //% }
//% } //% }
...@@ -776,7 +776,7 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -776,7 +776,7 @@ void GPBDictionaryReadEntry(id mapDictionary,
//%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, value, Raw) //%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, value, Raw)
//% //%
//%- (void)setValue:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key { //%- (void)setValue:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key {
//% if (!_validationFunc(value)) { //%DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) if (!_validationFunc(value)) {
//% [NSException raise:NSInvalidArgumentException //% [NSException raise:NSInvalidArgumentException
//% format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to set an unknown enum value (%d)", //% format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to set an unknown enum value (%d)",
//% value]; //% value];
...@@ -900,7 +900,7 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -900,7 +900,7 @@ void GPBDictionaryReadEntry(id mapDictionary,
//%} //%}
//% //%
//%- (void)set##ACCESSOR_NAME##VNAME$u##:(VALUE_TYPE)VNAME forKey:(KEY_TYPE##KisP$S##KisP)key { //%- (void)set##ACCESSOR_NAME##VNAME$u##:(VALUE_TYPE)VNAME forKey:(KEY_TYPE##KisP$S##KisP)key {
//% [_dictionary setObject:WRAPPED##VHELPER(VNAME) forKey:WRAPPED##KHELPER(key)]; //%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME, )##DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) [_dictionary setObject:WRAPPED##VHELPER(VNAME) forKey:WRAPPED##KHELPER(key)];
//% if (_autocreator) { //% if (_autocreator) {
//% GPBAutocreatedDictionaryModified(_autocreator, self); //% GPBAutocreatedDictionaryModified(_autocreator, self);
//% } //% }
...@@ -1171,6 +1171,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -1171,6 +1171,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
//% //%
//%PDDM-DEFINE GPBVALUE_POD(VALUE_NAME) //%PDDM-DEFINE GPBVALUE_POD(VALUE_NAME)
//%value##VALUE_NAME //%value##VALUE_NAME
//%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_POD(VALUE_NAME, EXTRA_INDENT)
// Empty
//%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_POD(KEY_NAME, EXTRA_INDENT)
// Empty
//%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD() //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD()
//% BOOL _valueSet[2]; //% BOOL _valueSet[2];
...@@ -1363,7 +1367,18 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -1363,7 +1367,18 @@ void GPBDictionaryReadEntry(id mapDictionary,
// Empty // Empty
//%PDDM-DEFINE GPBVALUE_OBJECT(VALUE_NAME) //%PDDM-DEFINE GPBVALUE_OBJECT(VALUE_NAME)
//%valueString //%valueString
//%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_OBJECT(VALUE_NAME, EXTRA_INDENT)
//%##EXTRA_INDENT$S## if (!##VALUE_NAME) {
//%##EXTRA_INDENT$S## [NSException raise:NSInvalidArgumentException
//%##EXTRA_INDENT$S## format:@"Attempting to add nil object to a Dictionary"];
//%##EXTRA_INDENT$S## }
//%
//%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_OBJECT(KEY_NAME, EXTRA_INDENT)
//%##EXTRA_INDENT$S## if (!##KEY_NAME) {
//%##EXTRA_INDENT$S## [NSException raise:NSInvalidArgumentException
//%##EXTRA_INDENT$S## format:@"Attempting to add nil key to a Dictionary"];
//%##EXTRA_INDENT$S## }
//%
//%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_OBJECT() //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_OBJECT()
// Empty // Empty
...@@ -1374,6 +1389,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -1374,6 +1389,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
//% self = [super init]; //% self = [super init];
//% if (self) { //% if (self) {
//% for (NSUInteger i = 0; i < count; ++i) { //% for (NSUInteger i = 0; i < count; ++i) {
//% if (!objects[i]) {
//% [NSException raise:NSInvalidArgumentException
//% format:@"Attempting to add nil object to a Dictionary"];
//% }
//% int idx = keys[i] ? 1 : 0; //% int idx = keys[i] ? 1 : 0;
//% [_values[idx] release]; //% [_values[idx] release];
//% _values[idx] = (VALUE_TYPE)[objects[i] retain]; //% _values[idx] = (VALUE_TYPE)[objects[i] retain];
...@@ -1433,6 +1452,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -1433,6 +1452,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
//%} //%}
//% //%
//%- (void)setObject:(VALUE_TYPE)object forKey:(BOOL)key { //%- (void)setObject:(VALUE_TYPE)object forKey:(BOOL)key {
//% if (!object) {
//% [NSException raise:NSInvalidArgumentException
//% format:@"Attempting to add nil object to a Dictionary"];
//% }
//% int idx = (key ? 1 : 0); //% int idx = (key ? 1 : 0);
//% [_values[idx] release]; //% [_values[idx] release];
//% _values[idx] = [object retain]; //% _values[idx] = [object retain];
...@@ -3239,6 +3262,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -3239,6 +3262,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
_dictionary = [[NSMutableDictionary alloc] init]; _dictionary = [[NSMutableDictionary alloc] init];
if (count && objects && keys) { if (count && objects && keys) {
for (NSUInteger i = 0; i < count; ++i) { for (NSUInteger i = 0; i < count; ++i) {
if (!objects[i]) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil object to a Dictionary"];
}
[_dictionary setObject:objects[i] forKey:@(keys[i])]; [_dictionary setObject:objects[i] forKey:@(keys[i])];
} }
} }
...@@ -3397,6 +3424,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -3397,6 +3424,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
} }
- (void)setObject:(id)object forKey:(uint32_t)key { - (void)setObject:(id)object forKey:(uint32_t)key {
if (!object) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil object to a Dictionary"];
}
[_dictionary setObject:object forKey:@(key)]; [_dictionary setObject:object forKey:@(key)];
if (_autocreator) { if (_autocreator) {
GPBAutocreatedDictionaryModified(_autocreator, self); GPBAutocreatedDictionaryModified(_autocreator, self);
...@@ -5195,6 +5226,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -5195,6 +5226,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
_dictionary = [[NSMutableDictionary alloc] init]; _dictionary = [[NSMutableDictionary alloc] init];
if (count && objects && keys) { if (count && objects && keys) {
for (NSUInteger i = 0; i < count; ++i) { for (NSUInteger i = 0; i < count; ++i) {
if (!objects[i]) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil object to a Dictionary"];
}
[_dictionary setObject:objects[i] forKey:@(keys[i])]; [_dictionary setObject:objects[i] forKey:@(keys[i])];
} }
} }
...@@ -5353,6 +5388,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -5353,6 +5388,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
} }
- (void)setObject:(id)object forKey:(int32_t)key { - (void)setObject:(id)object forKey:(int32_t)key {
if (!object) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil object to a Dictionary"];
}
[_dictionary setObject:object forKey:@(key)]; [_dictionary setObject:object forKey:@(key)];
if (_autocreator) { if (_autocreator) {
GPBAutocreatedDictionaryModified(_autocreator, self); GPBAutocreatedDictionaryModified(_autocreator, self);
...@@ -7151,6 +7190,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -7151,6 +7190,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
_dictionary = [[NSMutableDictionary alloc] init]; _dictionary = [[NSMutableDictionary alloc] init];
if (count && objects && keys) { if (count && objects && keys) {
for (NSUInteger i = 0; i < count; ++i) { for (NSUInteger i = 0; i < count; ++i) {
if (!objects[i]) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil object to a Dictionary"];
}
[_dictionary setObject:objects[i] forKey:@(keys[i])]; [_dictionary setObject:objects[i] forKey:@(keys[i])];
} }
} }
...@@ -7309,6 +7352,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -7309,6 +7352,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
} }
- (void)setObject:(id)object forKey:(uint64_t)key { - (void)setObject:(id)object forKey:(uint64_t)key {
if (!object) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil object to a Dictionary"];
}
[_dictionary setObject:object forKey:@(key)]; [_dictionary setObject:object forKey:@(key)];
if (_autocreator) { if (_autocreator) {
GPBAutocreatedDictionaryModified(_autocreator, self); GPBAutocreatedDictionaryModified(_autocreator, self);
...@@ -9107,6 +9154,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -9107,6 +9154,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
_dictionary = [[NSMutableDictionary alloc] init]; _dictionary = [[NSMutableDictionary alloc] init];
if (count && objects && keys) { if (count && objects && keys) {
for (NSUInteger i = 0; i < count; ++i) { for (NSUInteger i = 0; i < count; ++i) {
if (!objects[i]) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil object to a Dictionary"];
}
[_dictionary setObject:objects[i] forKey:@(keys[i])]; [_dictionary setObject:objects[i] forKey:@(keys[i])];
} }
} }
...@@ -9265,6 +9316,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -9265,6 +9316,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
} }
- (void)setObject:(id)object forKey:(int64_t)key { - (void)setObject:(id)object forKey:(int64_t)key {
if (!object) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil object to a Dictionary"];
}
[_dictionary setObject:object forKey:@(key)]; [_dictionary setObject:object forKey:@(key)];
if (_autocreator) { if (_autocreator) {
GPBAutocreatedDictionaryModified(_autocreator, self); GPBAutocreatedDictionaryModified(_autocreator, self);
...@@ -9336,6 +9391,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -9336,6 +9391,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
_dictionary = [[NSMutableDictionary alloc] init]; _dictionary = [[NSMutableDictionary alloc] init];
if (count && values && keys) { if (count && values && keys) {
for (NSUInteger i = 0; i < count; ++i) { for (NSUInteger i = 0; i < count; ++i) {
if (!keys[i]) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(values[i]) forKey:keys[i]]; [_dictionary setObject:@(values[i]) forKey:keys[i]];
} }
} }
...@@ -9474,6 +9533,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -9474,6 +9533,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
} }
- (void)setValue:(uint32_t)value forKey:(NSString *)key { - (void)setValue:(uint32_t)value forKey:(NSString *)key {
if (!key) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(value) forKey:key]; [_dictionary setObject:@(value) forKey:key];
if (_autocreator) { if (_autocreator) {
GPBAutocreatedDictionaryModified(_autocreator, self); GPBAutocreatedDictionaryModified(_autocreator, self);
...@@ -9542,6 +9605,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -9542,6 +9605,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
_dictionary = [[NSMutableDictionary alloc] init]; _dictionary = [[NSMutableDictionary alloc] init];
if (count && values && keys) { if (count && values && keys) {
for (NSUInteger i = 0; i < count; ++i) { for (NSUInteger i = 0; i < count; ++i) {
if (!keys[i]) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(values[i]) forKey:keys[i]]; [_dictionary setObject:@(values[i]) forKey:keys[i]];
} }
} }
...@@ -9680,6 +9747,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -9680,6 +9747,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
} }
- (void)setValue:(int32_t)value forKey:(NSString *)key { - (void)setValue:(int32_t)value forKey:(NSString *)key {
if (!key) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(value) forKey:key]; [_dictionary setObject:@(value) forKey:key];
if (_autocreator) { if (_autocreator) {
GPBAutocreatedDictionaryModified(_autocreator, self); GPBAutocreatedDictionaryModified(_autocreator, self);
...@@ -9748,6 +9819,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -9748,6 +9819,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
_dictionary = [[NSMutableDictionary alloc] init]; _dictionary = [[NSMutableDictionary alloc] init];
if (count && values && keys) { if (count && values && keys) {
for (NSUInteger i = 0; i < count; ++i) { for (NSUInteger i = 0; i < count; ++i) {
if (!keys[i]) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(values[i]) forKey:keys[i]]; [_dictionary setObject:@(values[i]) forKey:keys[i]];
} }
} }
...@@ -9886,6 +9961,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -9886,6 +9961,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
} }
- (void)setValue:(uint64_t)value forKey:(NSString *)key { - (void)setValue:(uint64_t)value forKey:(NSString *)key {
if (!key) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(value) forKey:key]; [_dictionary setObject:@(value) forKey:key];
if (_autocreator) { if (_autocreator) {
GPBAutocreatedDictionaryModified(_autocreator, self); GPBAutocreatedDictionaryModified(_autocreator, self);
...@@ -9954,6 +10033,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -9954,6 +10033,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
_dictionary = [[NSMutableDictionary alloc] init]; _dictionary = [[NSMutableDictionary alloc] init];
if (count && values && keys) { if (count && values && keys) {
for (NSUInteger i = 0; i < count; ++i) { for (NSUInteger i = 0; i < count; ++i) {
if (!keys[i]) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(values[i]) forKey:keys[i]]; [_dictionary setObject:@(values[i]) forKey:keys[i]];
} }
} }
...@@ -10092,6 +10175,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -10092,6 +10175,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
} }
- (void)setValue:(int64_t)value forKey:(NSString *)key { - (void)setValue:(int64_t)value forKey:(NSString *)key {
if (!key) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(value) forKey:key]; [_dictionary setObject:@(value) forKey:key];
if (_autocreator) { if (_autocreator) {
GPBAutocreatedDictionaryModified(_autocreator, self); GPBAutocreatedDictionaryModified(_autocreator, self);
...@@ -10160,6 +10247,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -10160,6 +10247,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
_dictionary = [[NSMutableDictionary alloc] init]; _dictionary = [[NSMutableDictionary alloc] init];
if (count && values && keys) { if (count && values && keys) {
for (NSUInteger i = 0; i < count; ++i) { for (NSUInteger i = 0; i < count; ++i) {
if (!keys[i]) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(values[i]) forKey:keys[i]]; [_dictionary setObject:@(values[i]) forKey:keys[i]];
} }
} }
...@@ -10298,6 +10389,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -10298,6 +10389,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
} }
- (void)setValue:(BOOL)value forKey:(NSString *)key { - (void)setValue:(BOOL)value forKey:(NSString *)key {
if (!key) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(value) forKey:key]; [_dictionary setObject:@(value) forKey:key];
if (_autocreator) { if (_autocreator) {
GPBAutocreatedDictionaryModified(_autocreator, self); GPBAutocreatedDictionaryModified(_autocreator, self);
...@@ -10366,6 +10461,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -10366,6 +10461,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
_dictionary = [[NSMutableDictionary alloc] init]; _dictionary = [[NSMutableDictionary alloc] init];
if (count && values && keys) { if (count && values && keys) {
for (NSUInteger i = 0; i < count; ++i) { for (NSUInteger i = 0; i < count; ++i) {
if (!keys[i]) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(values[i]) forKey:keys[i]]; [_dictionary setObject:@(values[i]) forKey:keys[i]];
} }
} }
...@@ -10504,6 +10603,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -10504,6 +10603,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
} }
- (void)setValue:(float)value forKey:(NSString *)key { - (void)setValue:(float)value forKey:(NSString *)key {
if (!key) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(value) forKey:key]; [_dictionary setObject:@(value) forKey:key];
if (_autocreator) { if (_autocreator) {
GPBAutocreatedDictionaryModified(_autocreator, self); GPBAutocreatedDictionaryModified(_autocreator, self);
...@@ -10572,6 +10675,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -10572,6 +10675,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
_dictionary = [[NSMutableDictionary alloc] init]; _dictionary = [[NSMutableDictionary alloc] init];
if (count && values && keys) { if (count && values && keys) {
for (NSUInteger i = 0; i < count; ++i) { for (NSUInteger i = 0; i < count; ++i) {
if (!keys[i]) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(values[i]) forKey:keys[i]]; [_dictionary setObject:@(values[i]) forKey:keys[i]];
} }
} }
...@@ -10710,6 +10817,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -10710,6 +10817,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
} }
- (void)setValue:(double)value forKey:(NSString *)key { - (void)setValue:(double)value forKey:(NSString *)key {
if (!key) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(value) forKey:key]; [_dictionary setObject:@(value) forKey:key];
if (_autocreator) { if (_autocreator) {
GPBAutocreatedDictionaryModified(_autocreator, self); GPBAutocreatedDictionaryModified(_autocreator, self);
...@@ -10802,6 +10913,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -10802,6 +10913,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
_validationFunc = (func != NULL ? func : DictDefault_IsValidValue); _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
if (count && rawValues && keys) { if (count && rawValues && keys) {
for (NSUInteger i = 0; i < count; ++i) { for (NSUInteger i = 0; i < count; ++i) {
if (!keys[i]) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(rawValues[i]) forKey:keys[i]]; [_dictionary setObject:@(rawValues[i]) forKey:keys[i]];
} }
} }
...@@ -10982,6 +11097,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -10982,6 +11097,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
} }
- (void)setRawValue:(int32_t)value forKey:(NSString *)key { - (void)setRawValue:(int32_t)value forKey:(NSString *)key {
if (!key) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
[_dictionary setObject:@(value) forKey:key]; [_dictionary setObject:@(value) forKey:key];
if (_autocreator) { if (_autocreator) {
GPBAutocreatedDictionaryModified(_autocreator, self); GPBAutocreatedDictionaryModified(_autocreator, self);
...@@ -10997,6 +11116,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -10997,6 +11116,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
} }
- (void)setValue:(int32_t)value forKey:(NSString *)key { - (void)setValue:(int32_t)value forKey:(NSString *)key {
if (!key) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil key to a Dictionary"];
}
if (!_validationFunc(value)) { if (!_validationFunc(value)) {
[NSException raise:NSInvalidArgumentException [NSException raise:NSInvalidArgumentException
format:@"GPBStringEnumDictionary: Attempt to set an unknown enum value (%d)", format:@"GPBStringEnumDictionary: Attempt to set an unknown enum value (%d)",
...@@ -12754,6 +12877,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -12754,6 +12877,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
self = [super init]; self = [super init];
if (self) { if (self) {
for (NSUInteger i = 0; i < count; ++i) { for (NSUInteger i = 0; i < count; ++i) {
if (!objects[i]) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil object to a Dictionary"];
}
int idx = keys[i] ? 1 : 0; int idx = keys[i] ? 1 : 0;
[_values[idx] release]; [_values[idx] release];
_values[idx] = (id)[objects[i] retain]; _values[idx] = (id)[objects[i] retain];
...@@ -12932,6 +13059,10 @@ void GPBDictionaryReadEntry(id mapDictionary, ...@@ -12932,6 +13059,10 @@ void GPBDictionaryReadEntry(id mapDictionary,
} }
- (void)setObject:(id)object forKey:(BOOL)key { - (void)setObject:(id)object forKey:(BOOL)key {
if (!object) {
[NSException raise:NSInvalidArgumentException
format:@"Attempting to add nil object to a Dictionary"];
}
int idx = (key ? 1 : 0); int idx = (key ? 1 : 0);
[_values[idx] release]; [_values[idx] release];
_values[idx] = [object retain]; _values[idx] = [object retain];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment