TagAdA

Changeset 219


Ignore:
Timestamp:
Sep 30, 2010, 11:17:41 AM (8 years ago)
Author:
Joel Lopes Da Silva
Message:

Moving back to using stack based character arrays in _TGDFileHashCreateWithPath for higher efficiency. I had to allocate those arrays on the heap in order to avoid crashes at runtime, when the app was compiled with clang. This was actually a bug in the clang compiler, which wasn't dealing with the stack correctly when it encountered stack based variable length arrays. This bug is fixed now: http://llvm.org/viewvc/llvm-project?view=rev&revision=113822

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/mac/Sources/Model/TGDFileHash.c

    r197 r219  
    138138                                              TGDHashComputationContext *context) {
    139139   
    140     // Declare needed variables
     140    // Declare needed variables and buffers
    141141    CFStringRef result = NULL;
    142142    CFReadStreamRef readStream = NULL;
    143     unsigned char *digest = NULL;
     143    unsigned char digest[context->digestLength];
     144    char hash[2 * context->digestLength + 1];
    144145   
    145146    // Get the file URL
     
    157158    bool didSucceed = (bool)CFReadStreamOpen(readStream);
    158159    if (!didSucceed) goto done;
    159    
    160     // Allocate the buffer for the hash digest
    161     digest =
    162         (unsigned char *)malloc(context->digestLength * sizeof(unsigned char *));
    163     if (!digest) goto done;
    164160   
    165161    // Initialize the hash object
     
    198194   
    199195    // Compute the string result
    200     char *hash = (char *)malloc(2 * context->digestLength + 1);
    201     if (!hash) goto done;
    202196    for (size_t i = 0; i < context->digestLength; ++i) {
    203197        snprintf(hash + (2 * i), 3, "%02x", (int)(digest[i]));
    204198    }
    205     free(digest);
    206     digest = NULL;
    207199    result = CFStringCreateWithCString(kCFAllocatorDefault,
    208200                                       (const char *)hash,
    209201                                       kCFStringEncodingUTF8);
    210     free(hash);
    211202   
    212203done:
    213204   
    214     if (digest) {
    215         free(digest);
    216     }
    217205    if (readStream) {
    218206        CFReadStreamClose(readStream);
Note: See TracChangeset for help on using the changeset viewer.
Copyright © 2008-2017 The TagAdA Team. All rights reserved.