From: Andrew McGeachie Date: Thu, 23 Jul 2009 18:12:18 +0000 (+0000) Subject: THRIFT-548. malloc our temporary buffer, rather than creating it on the stack. X-Git-Tag: 0.2.0~62 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=061722b4fd8a6aed2e8dbc98f0bbbffc9e71e72c;p=common%2Fthrift.git THRIFT-548. malloc our temporary buffer, rather than creating it on the stack. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@797175 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/cocoa/src/protocol/TBinaryProtocol.m b/lib/cocoa/src/protocol/TBinaryProtocol.m index ba7f4629..5999e250 100644 --- a/lib/cocoa/src/protocol/TBinaryProtocol.m +++ b/lib/cocoa/src/protocol/TBinaryProtocol.m @@ -90,10 +90,18 @@ static TBinaryProtocolFactory * gSharedFactory = nil; - (NSString *) readStringBody: (int) size { - char buff[size+1]; - [mTransport readAll: (uint8_t *) buff offset: 0 length: size]; - buff[size] = 0; - return [NSString stringWithUTF8String: buff]; + char * buffer = malloc(size+1); + if (!buffer) { + @throw [TProtocolException exceptionWithName: @"TProtocolException" + reason: [NSString stringWithFormat: @"Unable to allocate memory in %s, size: %i", + __PRETTY_FUNCTION__, + size]];; + } + [mTransport readAll: (uint8_t *) buffer offset: 0 length: size]; + buffer[size] = 0; + NSString * result = [NSString stringWithUTF8String: buffer]; + free(buffer); + return result; }