From 8ec5f0ca3cbbf3e9ae6515afffe09184d4029ced Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Sat, 28 Jun 2014 21:17:37 -0400 Subject: [PATCH] Avoid variable-length arrays in C. --- SUBinaryDeltaCommon.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SUBinaryDeltaCommon.m b/SUBinaryDeltaCommon.m index 25768c60..e2fa1c46 100644 --- a/SUBinaryDeltaCommon.m +++ b/SUBinaryDeltaCommon.m @@ -47,11 +47,13 @@ NSString *temporaryFilename(NSString *base) { NSString *template = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.XXXXXXXXXX", base]]; const char *fsrepr = [template fileSystemRepresentation]; - char buffer[strlen(fsrepr)+1]; + char *buffer = (char *)malloc(strlen(fsrepr) + 1); strcpy(buffer, fsrepr); // mkstemp() can't be used, beause it returns a file descriptor, and XAR API requires a filename - return stringWithFileSystemRepresentation(mktemp(buffer)); + NSString *ret = stringWithFileSystemRepresentation(mktemp(buffer)); + free(buffer); + return ret; } static void _hashOfBuffer(unsigned char *hash, const char* buffer, ssize_t bufferLength)