raising exception if malloc is null

This commit is contained in:
Antoine Cœur
2017-10-30 10:05:37 +08:00
parent 924b9240d3
commit 82af68a7d5
+13 -4
View File
@@ -858,10 +858,12 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
+ (NSString *)_filenameStringWithCString:(const char *)filename size:(uint16_t)size_filename
{
// attempting unicode encoding
NSString * strPath = @(filename);
if (strPath) {
return strPath;
}
// if filename is non-unicode, detect and transform Encoding
NSData *data = [NSData dataWithBytes:(const void *)filename length:sizeof(unsigned char) * size_filename];
#ifdef __MAC_10_13
@@ -887,11 +889,13 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
}
}
}
if (!strPath) {
// if filename encoding is non-detected, we default to something based on data
// _hexString is more readable than _base64RFC4648 for debugging unknown encodings
strPath = [data _hexString];
if (strPath) {
return strPath;
}
// if filename encoding is non-detected, we default to something based on data
// _hexString is more readable than _base64RFC4648 for debugging unknown encodings
strPath = [data _hexString];
return strPath;
}
@@ -1043,6 +1047,11 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo)
NSUInteger length = self.length;
const unsigned char *bytes = self.bytes;
char *chars = malloc(length * 2);
if (chars == NULL) {
// we directly raise an exception instead of using NSAssert to make sure assertion is not disabled as this is irrecoverable
[NSException raise:@"NSInternalInconsistencyException" format:@"failed malloc" arguments:nil];
return nil;
}
char *s = chars;
NSUInteger i = length;
while (i--) {