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 @@
GPBUnknownFieldSet* bizarroFields =
[[[GPBUnknownFieldSet alloc] init] autorelease];
NSUInteger count = [unknownFields_ countOfFields];
int32_t tags[count];
[unknownFields_ getTags:tags];
for (NSUInteger i = 0; i < count; ++i) {
int32_t tag = tags[i];
GPBUnknownField* field = [unknownFields_ getField:tag];
if (field.varintList.count == 0) {
// Original field is not a varint, so use a varint.
GPBUnknownField* varintField =
[[[GPBUnknownField alloc] initWithNumber:tag] autorelease];
[varintField addVarint:1];
[bizarroFields addField:varintField];
} else {
// Original field *is* a varint, so use something else.
GPBUnknownField* fixed32Field =
[[[GPBUnknownField alloc] initWithNumber:tag] autorelease];
[fixed32Field addFixed32:1];
[bizarroFields addField:fixed32Field];
int32_t *tags = malloc(count * sizeof(int32_t));
if (!tags) {
XCTFail(@"Failed to make scratch buffer for testing");
return [NSData data];
}
@try {
[unknownFields_ getTags:tags];
for (NSUInteger i = 0; i < count; ++i) {
int32_t tag = tags[i];
GPBUnknownField* field = [unknownFields_ getField:tag];
if (field.varintList.count == 0) {
// Original field is not a varint, so use a varint.
GPBUnknownField* varintField =
[[[GPBUnknownField alloc] initWithNumber:tag] autorelease];
[varintField addVarint:1];
[bizarroFields addField:varintField];
} 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];
}
......
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