Skip to content

Commit

Permalink
[ObjC] Use a local to avoid warnings in 32bit builds.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thomasvl authored and zhangskz committed Feb 12, 2024
1 parent 9d1bc10 commit 9dc736d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions objectivec/GPBCodedInputStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
if (size == 0) {
result = @"";
} else {
CheckSize(state, size);
size_t size2 = (size_t)size; // Cast safe on 32bit because of CheckFieldSize() above.
CheckSize(state, size2);
result = [[NSString alloc] initWithBytes:&state->bytes[state->bufferPos]
length:ns_size
encoding:NSUTF8StringEncoding];
Expand All @@ -239,8 +240,9 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) {
uint64_t size = GPBCodedInputStreamReadUInt64(state);
CheckFieldSize(size);
size_t size2 = (size_t)size; // Cast safe on 32bit because of CheckFieldSize() above.
CheckSize(state, size2);
NSUInteger ns_size = (NSUInteger)size;
CheckSize(state, size);
NSData *result = [[NSData alloc] initWithBytes:state->bytes + state->bufferPos length:ns_size];
state->bufferPos += size;
return result;
Expand All @@ -249,8 +251,9 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(GPBCodedInputStreamState *state) {
uint64_t size = GPBCodedInputStreamReadUInt64(state);
CheckFieldSize(size);
size_t size2 = (size_t)size; // Cast safe on 32bit because of CheckFieldSize() above.
CheckSize(state, size2);
NSUInteger ns_size = (NSUInteger)size;
CheckSize(state, size);
// Cast is safe because freeWhenDone is NO.
NSData *result = [[NSData alloc] initWithBytesNoCopy:(void *)(state->bytes + state->bufferPos)
length:ns_size
Expand Down Expand Up @@ -338,7 +341,8 @@ - (BOOL)skipField:(int32_t)tag {
case GPBWireFormatLengthDelimited: {
uint64_t size = GPBCodedInputStreamReadUInt64(&state_);
CheckFieldSize(size);
SkipRawData(&state_, size);
size_t size2 = (size_t)size; // Cast safe on 32bit because of CheckFieldSize() above.
SkipRawData(&state_, size2);
return YES;
}
case GPBWireFormatStartGroup:
Expand Down Expand Up @@ -441,7 +445,8 @@ - (void)readMessage:(GPBMessage *)message
CheckRecursionLimit(&state_);
uint64_t length = GPBCodedInputStreamReadUInt64(&state_);
CheckFieldSize(length);
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
size_t length2 = (size_t)length; // Cast safe on 32bit because of CheckFieldSize() above.
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length2);
++state_.recursionDepth;
[message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry];
GPBCodedInputStreamCheckLastTagWas(&state_, 0);
Expand All @@ -456,7 +461,8 @@ - (void)readMapEntry:(id)mapDictionary
CheckRecursionLimit(&state_);
uint64_t length = GPBCodedInputStreamReadUInt64(&state_);
CheckFieldSize(length);
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
size_t length2 = (size_t)length; // Cast safe on 32bit because of CheckFieldSize() above.
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length2);
++state_.recursionDepth;
GPBDictionaryReadEntry(mapDictionary, self, extensionRegistry, field, parentMessage);
GPBCodedInputStreamCheckLastTagWas(&state_, 0);
Expand Down

0 comments on commit 9dc736d

Please sign in to comment.