Commit 065fa2f3 authored by Thomas Van Lenten's avatar Thomas Van Lenten

Remove use of VLA.

VLAs complicate static analysis and bloat stack size. Replace VLA allocation
with calls to malloc and free.  This will alos the code to build with -Wvla.
parent 53a814a0
...@@ -156,25 +156,34 @@ ...@@ -156,25 +156,34 @@
GPBUnknownFieldSet* bizarroFields = GPBUnknownFieldSet* bizarroFields =
[[[GPBUnknownFieldSet alloc] init] autorelease]; [[[GPBUnknownFieldSet alloc] init] autorelease];
NSUInteger count = [unknownFields_ countOfFields]; NSUInteger count = [unknownFields_ countOfFields];
int32_t tags[count]; int32_t *tags = malloc(count * sizeof(int32_t));
[unknownFields_ getTags:tags]; if (!tags) {
for (NSUInteger i = 0; i < count; ++i) { XCTFail(@"Failed to make scratch buffer for testing");
int32_t tag = tags[i]; return [NSData data];
GPBUnknownField* field = [unknownFields_ getField:tag]; }
if (field.varintList.count == 0) { @try {
// Original field is not a varint, so use a varint. [unknownFields_ getTags:tags];
GPBUnknownField* varintField = for (NSUInteger i = 0; i < count; ++i) {
[[[GPBUnknownField alloc] initWithNumber:tag] autorelease]; int32_t tag = tags[i];
[varintField addVarint:1]; GPBUnknownField* field = [unknownFields_ getField:tag];
[bizarroFields addField:varintField]; if (field.varintList.count == 0) {
} else { // Original field is not a varint, so use a varint.
// Original field *is* a varint, so use something else. GPBUnknownField* varintField =
GPBUnknownField* fixed32Field = [[[GPBUnknownField alloc] initWithNumber:tag] autorelease];
[[[GPBUnknownField alloc] initWithNumber:tag] autorelease]; [varintField addVarint:1];
[fixed32Field addFixed32:1]; [bizarroFields addField:varintField];
[bizarroFields addField:fixed32Field]; } else {
// Original field *is* a varint, so use something else.
GPBUnknownField* fixed32Field =
[[[GPBUnknownField alloc] initWithNumber:tag] autorelease];
[fixed32Field addFixed32:1];
[bizarroFields addField:fixed32Field];
}
} }
} }
@finally {
free(tags);
}
return [bizarroFields data]; return [bizarroFields data];
} }
......
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