From 509bc3a2fa133089743f8055e6fc0c2082913268 Mon Sep 17 00:00:00 2001 From: Themis wang Date: Mon, 30 Dec 2024 12:00:40 -0500 Subject: [PATCH] fix comment and migrate to call for session --- Crashlytics/Crashlytics/Helpers/FIRCLSAllocate.c | 16 ++++++++-------- Crashlytics/Crashlytics/Helpers/FIRCLSFile.m | 6 +++--- Crashlytics/Crashlytics/Helpers/FIRCLSUtility.m | 2 +- .../Models/Record/FIRCLSReportAdapter.m | 6 +++--- .../SourcesObjC/NanoPB/FIRSESNanoPBHelpers.h | 4 ++-- .../SourcesObjC/NanoPB/FIRSESNanoPBHelpers.m | 8 ++++---- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Crashlytics/Crashlytics/Helpers/FIRCLSAllocate.c b/Crashlytics/Crashlytics/Helpers/FIRCLSAllocate.c index acf78d98496..6c04a7d4f77 100644 --- a/Crashlytics/Crashlytics/Helpers/FIRCLSAllocate.c +++ b/Crashlytics/Crashlytics/Helpers/FIRCLSAllocate.c @@ -56,7 +56,7 @@ FIRCLSAllocatorRef FIRCLSAllocatorCreate(size_t writableSpace, size_t readableSp } // Make one big, continuous allocation, adding additional pages for our guards. Note - // that we cannot use malloc (or valloc) in this case, because we need to assert full + // that we cannot use malloc, calloc (or valloc) in this case, because we need to assert full // ownership over these allocations. mmap is a much better choice. We also mark these // pages as MAP_NOCACHE. allocationSize = writableRegion.size + readableRegion.size + pageSize * 3; @@ -174,10 +174,10 @@ void* FIRCLSAllocatorSafeAllocateFromRegion(FIRCLSAllocationRegion* region, size // this shouldn't happen unless we make a mistake with our size pre-computations if ((uintptr_t)originalCursor - (uintptr_t)region->start + size > region->size) { - FIRCLSSDKLog("Unable to allocate sufficient memory, falling back to malloc\n"); + FIRCLSSDKLog("Unable to allocate sufficient memory, falling back to calloc\n"); void* ptr = calloc(1, size); if (!ptr) { - FIRCLSSDKLog("Unable to malloc in FIRCLSAllocatorSafeAllocateFromRegion\n"); + FIRCLSSDKLog("Unable to calloc in FIRCLSAllocatorSafeAllocateFromRegion\n"); return NULL; } return ptr; @@ -195,21 +195,21 @@ void* FIRCLSAllocatorSafeAllocate(FIRCLSAllocatorRef allocator, FIRCLSAllocationRegion* region; if (!allocator) { - // fall back to malloc in this case - FIRCLSSDKLog("Allocator invalid, falling back to malloc\n"); + // fall back to calloc in this case + FIRCLSSDKLog("Allocator invalid, falling back to calloc\n"); void* ptr = calloc(1, size); if (!ptr) { - FIRCLSSDKLog("Unable to malloc in FIRCLSAllocatorSafeAllocate\n"); + FIRCLSSDKLog("Unable to calloc in FIRCLSAllocatorSafeAllocate\n"); return NULL; } return ptr; } if (allocator->protectionEnabled) { - FIRCLSSDKLog("Allocator already protected, falling back to malloc\n"); + FIRCLSSDKLog("Allocator already protected, falling back to calloc\n"); void* ptr = calloc(1, size); if (!ptr) { - FIRCLSSDKLog("Unable to malloc in FIRCLSAllocatorSafeAllocate\n"); + FIRCLSSDKLog("Unable to calloc in FIRCLSAllocatorSafeAllocate\n"); return NULL; } return ptr; diff --git a/Crashlytics/Crashlytics/Helpers/FIRCLSFile.m b/Crashlytics/Crashlytics/Helpers/FIRCLSFile.m index 1f4d2a0c836..6a2b7fa3a19 100644 --- a/Crashlytics/Crashlytics/Helpers/FIRCLSFile.m +++ b/Crashlytics/Crashlytics/Helpers/FIRCLSFile.m @@ -76,7 +76,7 @@ static bool FIRCLSFileInit( if (bufferWrites) { file->writeBuffer = calloc(1, FIRCLSWriteBufferLength * sizeof(char)); if (!file->writeBuffer) { - FIRCLSErrorLog(@"Unable to malloc in FIRCLSFileInit"); + FIRCLSErrorLog(@"Unable to calloc in FIRCLSFileInit"); return false; } @@ -671,7 +671,7 @@ void FIRCLSFileWriteArrayEntryHexEncodedString(FIRCLSFile* file, const char* val char* encodedBuffer = calloc(1, length * 2 + 1); if (!encodedBuffer) { - FIRCLSErrorLog(@"Unable to malloc in FIRCLSFileHexEncodeString"); + FIRCLSErrorLog(@"Unable to calloc in FIRCLSFileHexEncodeString"); return nil; } @@ -695,7 +695,7 @@ void FIRCLSFileWriteArrayEntryHexEncodedString(FIRCLSFile* file, const char* val size_t length = strlen(string); char* decodedBuffer = calloc(1, length); // too long, but safe if (!decodedBuffer) { - FIRCLSErrorLog(@"Unable to malloc in FIRCLSFileHexDecodeString"); + FIRCLSErrorLog(@"Unable to calloc in FIRCLSFileHexDecodeString"); return nil; } diff --git a/Crashlytics/Crashlytics/Helpers/FIRCLSUtility.m b/Crashlytics/Crashlytics/Helpers/FIRCLSUtility.m index 21e87ac66fd..7edb657aeaa 100644 --- a/Crashlytics/Crashlytics/Helpers/FIRCLSUtility.m +++ b/Crashlytics/Crashlytics/Helpers/FIRCLSUtility.m @@ -188,7 +188,7 @@ void FIRCLSRedactUUID(char* value) { buffer = calloc(1, sizeof(char) * size); if (!buffer) { - FIRCLSErrorLog(@"Unable to malloc in FIRCLSNSDataToNSString"); + FIRCLSErrorLog(@"Unable to calloc in FIRCLSNSDataToNSString"); return nil; } diff --git a/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m b/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m index 543c6bfc718..6ee57270ef8 100644 --- a/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m +++ b/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m @@ -236,7 +236,7 @@ - (google_crashlytics_Platforms)protoPlatformFromString:(NSString *)str { } } -/** Mallocs a pb_bytes_array and copies the given NSString's bytes into the bytes array. +/** Callocs a pb_bytes_array and copies the given NSString's bytes into the bytes array. * @note Memory needs to be freed manually, through pb_free or pb_release. * @param string The string to encode as pb_bytes. */ @@ -251,12 +251,12 @@ - (google_crashlytics_Platforms)protoPlatformFromString:(NSString *)str { return FIRCLSEncodeData(stringBytes); } -/** Mallocs a pb_bytes_array and copies the given NSData bytes into the bytes array. +/** Callocs a pb_bytes_array and copies the given NSData bytes into the bytes array. * @note Memory needs to be free manually, through pb_free or pb_release. * @param data The data to copy into the new bytes array. */ pb_bytes_array_t *FIRCLSEncodeData(NSData *data) { - // We have received couple security tickets before for using malloc here. + // We have received couple security tickets before for using calloc here. // Here is a short explaination on how it is calculated so buffer overflow is prevented: // We will alloc an amount of memeory for struct `pb_bytes_array_t`, this struct contains two // attributes: diff --git a/FirebaseSessions/SourcesObjC/NanoPB/FIRSESNanoPBHelpers.h b/FirebaseSessions/SourcesObjC/NanoPB/FIRSESNanoPBHelpers.h index e07f0e344ed..a0d5a6f8c78 100644 --- a/FirebaseSessions/SourcesObjC/NanoPB/FIRSESNanoPBHelpers.h +++ b/FirebaseSessions/SourcesObjC/NanoPB/FIRSESNanoPBHelpers.h @@ -49,12 +49,12 @@ NSData* _Nullable FIRSESEncodeProto(const pb_field_t fields[], NSError** error); #pragma clang diagnostic pop -/// Mallocs a pb_bytes_array and copies the given NSData bytes into the bytes array. +/// Callocs a pb_bytes_array and copies the given NSData bytes into the bytes array. /// @note Memory needs to be freed manually, through pb_free or pb_release. /// @param data The data to copy into the new bytes array. pb_bytes_array_t* _Nullable FIRSESEncodeData(NSData* _Nullable data); -/// Mallocs a pb_bytes_array and copies the given NSString's bytes into the bytes array. +/// Callocs a pb_bytes_array and copies the given NSString's bytes into the bytes array. /// @note Memory needs to be freed manually, through pb_free or pb_release. /// @param string The string to encode as pb_bytes. pb_bytes_array_t* _Nullable FIRSESEncodeString(NSString* _Nullable string); diff --git a/FirebaseSessions/SourcesObjC/NanoPB/FIRSESNanoPBHelpers.m b/FirebaseSessions/SourcesObjC/NanoPB/FIRSESNanoPBHelpers.m index 6440ec4d886..17dd086157a 100644 --- a/FirebaseSessions/SourcesObjC/NanoPB/FIRSESNanoPBHelpers.m +++ b/FirebaseSessions/SourcesObjC/NanoPB/FIRSESNanoPBHelpers.m @@ -87,12 +87,12 @@ void nanopb_free(void *_Nullable ptr) { } #pragma clang diagnostic pop -/** Mallocs a pb_bytes_array and copies the given NSData bytes into the bytes array. +/** Callocs a pb_bytes_array and copies the given NSData bytes into the bytes array. * @note Memory needs to be free manually, through pb_free or pb_release. * @param data The data to copy into the new bytes array. */ pb_bytes_array_t *_Nullable FIRSESEncodeData(NSData *_Nullable data) { - pb_bytes_array_t *pbBytes = malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(data.length)); + pb_bytes_array_t *pbBytes = calloc(1, PB_BYTES_ARRAY_T_ALLOCSIZE(data.length)); if (pbBytes == NULL) { return NULL; } @@ -101,7 +101,7 @@ void nanopb_free(void *_Nullable ptr) { return pbBytes; } -/** Mallocs a pb_bytes_array and copies the given NSString's bytes into the bytes array. +/** Callocs a pb_bytes_array and copies the given NSString's bytes into the bytes array. * @note Memory needs to be freed manually, through pb_free or pb_release. * @param string The string to encode as pb_bytes. */ @@ -174,7 +174,7 @@ pb_size_t FIRSESGetAppleApplicationInfoTag(void) { size_t size; sysctlbyname(sysctlKey, NULL, &size, NULL, 0); if (size > 0) { - char *entryValueCStr = malloc(size); + char *entryValueCStr = calloc(1, size); sysctlbyname(sysctlKey, entryValueCStr, &size, NULL, 0); entryValue = [NSString stringWithCString:entryValueCStr encoding:NSUTF8StringEncoding]; free(entryValueCStr);