Skip to content

Commit 366c991

Browse files
committed
Check return from calloc
1 parent 388f4bc commit 366c991

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

CoreFoundation/Base.subproj/CFUtilities.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,12 @@ void CFLog1(CFLogLevel lev, CFStringRef message) {
790790

791791
if (maxLength > sizeof(stack_buffer) / sizeof(stack_buffer[0])) {
792792
buffer = calloc(sizeof(char), maxLength);
793-
if (!buffer) {
794-
__android_log_print(ANDROID_LOG_ERROR, tag, "Unable to allocate %d bytes for log message - truncating.", (int)maxLength);
795-
maxLength = sizeof(stack_buffer) / sizeof(stack_buffer[0]);
796-
buffer = &stack_buffer[0];
797-
}
793+
if (!buffer) {
794+
__android_log_print(ANDROID_LOG_ERROR, tag, "Unable to allocate %d bytes for log message - truncating.", (int)maxLength);
795+
maxLength = sizeof(stack_buffer) / sizeof(stack_buffer[0]);
796+
buffer = &stack_buffer[0];
797+
buffer[maxLength-1] = '\000';
798+
}
798799
}
799800

800801
if (maxLength == 1) {

0 commit comments

Comments
 (0)