Skip to content

Commit 29cf6cc

Browse files
authored
Merge pull request #655 from Concoction/master
2 parents cc5985e + 366c991 commit 29cf6cc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

CoreFoundation/Base.subproj/CFUtilities.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,16 @@ void CFLog1(CFLogLevel lev, CFStringRef message) {
786786
char *buffer = &stack_buffer[0];
787787
CFStringEncoding encoding = kCFStringEncodingUTF8;
788788
CFIndex maxLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(message), encoding) + 1;
789+
const char *tag = "Swift"; // process name not available from NDK
789790

790791
if (maxLength > sizeof(stack_buffer) / sizeof(stack_buffer[0])) {
791792
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+
buffer[maxLength-1] = '\000';
798+
}
792799
}
793800

794801
if (maxLength == 1) {
@@ -799,7 +806,6 @@ void CFLog1(CFLogLevel lev, CFStringRef message) {
799806
else
800807
CFStringGetCString(message, buffer, maxLength, encoding);
801808

802-
const char *tag = "Swift"; // process name not available from NDK
803809
__android_log_print(priority, tag, "%s", buffer);
804810

805811
if (buffer != &stack_buffer[0]) free(buffer);

0 commit comments

Comments
 (0)