Skip to content

Commit 9dc736d

Browse files
thomasvlzhangskz
authored andcommitted
[ObjC] Use a local to avoid warnings in 32bit builds.
CocoaPods fails spec validation for some warnings, so use a local to avoid warnings for 64->32bit implicit conversions. This comes up for watchOS builds. PiperOrigin-RevId: 601849919
1 parent 9d1bc10 commit 9dc736d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

objectivec/GPBCodedInputStream.m

+12-6
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
219219
if (size == 0) {
220220
result = @"";
221221
} else {
222-
CheckSize(state, size);
222+
size_t size2 = (size_t)size; // Cast safe on 32bit because of CheckFieldSize() above.
223+
CheckSize(state, size2);
223224
result = [[NSString alloc] initWithBytes:&state->bytes[state->bufferPos]
224225
length:ns_size
225226
encoding:NSUTF8StringEncoding];
@@ -239,8 +240,9 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
239240
NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) {
240241
uint64_t size = GPBCodedInputStreamReadUInt64(state);
241242
CheckFieldSize(size);
243+
size_t size2 = (size_t)size; // Cast safe on 32bit because of CheckFieldSize() above.
244+
CheckSize(state, size2);
242245
NSUInteger ns_size = (NSUInteger)size;
243-
CheckSize(state, size);
244246
NSData *result = [[NSData alloc] initWithBytes:state->bytes + state->bufferPos length:ns_size];
245247
state->bufferPos += size;
246248
return result;
@@ -249,8 +251,9 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
249251
NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(GPBCodedInputStreamState *state) {
250252
uint64_t size = GPBCodedInputStreamReadUInt64(state);
251253
CheckFieldSize(size);
254+
size_t size2 = (size_t)size; // Cast safe on 32bit because of CheckFieldSize() above.
255+
CheckSize(state, size2);
252256
NSUInteger ns_size = (NSUInteger)size;
253-
CheckSize(state, size);
254257
// Cast is safe because freeWhenDone is NO.
255258
NSData *result = [[NSData alloc] initWithBytesNoCopy:(void *)(state->bytes + state->bufferPos)
256259
length:ns_size
@@ -338,7 +341,8 @@ - (BOOL)skipField:(int32_t)tag {
338341
case GPBWireFormatLengthDelimited: {
339342
uint64_t size = GPBCodedInputStreamReadUInt64(&state_);
340343
CheckFieldSize(size);
341-
SkipRawData(&state_, size);
344+
size_t size2 = (size_t)size; // Cast safe on 32bit because of CheckFieldSize() above.
345+
SkipRawData(&state_, size2);
342346
return YES;
343347
}
344348
case GPBWireFormatStartGroup:
@@ -441,7 +445,8 @@ - (void)readMessage:(GPBMessage *)message
441445
CheckRecursionLimit(&state_);
442446
uint64_t length = GPBCodedInputStreamReadUInt64(&state_);
443447
CheckFieldSize(length);
444-
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
448+
size_t length2 = (size_t)length; // Cast safe on 32bit because of CheckFieldSize() above.
449+
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length2);
445450
++state_.recursionDepth;
446451
[message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry];
447452
GPBCodedInputStreamCheckLastTagWas(&state_, 0);
@@ -456,7 +461,8 @@ - (void)readMapEntry:(id)mapDictionary
456461
CheckRecursionLimit(&state_);
457462
uint64_t length = GPBCodedInputStreamReadUInt64(&state_);
458463
CheckFieldSize(length);
459-
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
464+
size_t length2 = (size_t)length; // Cast safe on 32bit because of CheckFieldSize() above.
465+
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length2);
460466
++state_.recursionDepth;
461467
GPBDictionaryReadEntry(mapDictionary, self, extensionRegistry, field, parentMessage);
462468
GPBCodedInputStreamCheckLastTagWas(&state_, 0);

0 commit comments

Comments
 (0)