git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@797175
13f79535-47bb-0310-9956-
ffa450edef68
- (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;
}