IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 12, 2004, 9:04:26 AM (22 years ago)
Author:
desonia
Message:

added buffer overflow detection to psMemory, and tests needed to be changed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/sysUtils/tst_psMemory.c

    r640 r647  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-05-11 20:52:33 $
     8 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-05-12 19:04:26 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3232static int TPrealloc(void);
    3333static int TPallocCallback(void);
    34 static long memAllocateCallback(const psMemBlock *ptr);
    35 static long memFreeCallback(const psMemBlock *ptr);
     34static psMemoryId memAllocateCallback(const psMemBlock *ptr);
     35static psMemoryId memFreeCallback(const psMemBlock *ptr);
    3636int TPcheckLeaks(void);
    3737int TPmemCorruption(void);
     
    4141static int allocCallbackCalled = 0;
    4242static int freeCallbackCalled = 0;
    43 
    44 bool TPOutOfMemoryExhaustedCallbackCalled = false;
     43static int exhaustedCallbackCalled = 0;
    4544
    4645testDescription tests[] = {
    4746                              {TPCheckBufferPositive,"449-TPCheckBufferPositive",0},
    48                               {TPOutOfMemory,"450-TPOutOfMemory",0},
     47                              {TPOutOfMemory,"450-TPOutOfMemory",6},
    4948                              {TPrealloc,"451-TPrealloc",0},
    5049                              {TPallocCallback,"452/453-TPallocCallback",0},
     
    5857{
    5958    psSetLogLevel(PS_LOG_INFO);
    60 
    6159    if (! runTestSuite(stderr,"psMemory",tests)) {
    6260        psAbort(__FILE__,"One or more tests failed");
     
    168166             "the psMemExhaustedCallback.\n");
    169167
    170     TPOutOfMemoryExhaustedCallbackCalled = false;
     168    exhaustedCallbackCalled = 0;
    171169
    172170    cb = psMemExhaustedCallbackSet(TPOutOfMemoryExhaustedCallback);
    173171
    174     mem = (int*) psAlloc(INT_MAX);
     172    mem = (int*) psAlloc(LONG_MAX);
    175173
    176174    psMemExhaustedCallbackSet(cb);
    177175
    178     if (!TPOutOfMemoryExhaustedCallbackCalled) {
     176    if (exhaustedCallbackCalled == 0) {
    179177        psError(__FILE__,"Called psAlloc with HUGE memory requirement and survived in %s!",__func__);
    180178        return 1;
     
    187185
    188186    return 0;
    189 }
    190 
    191 
    192 
    193 void* TPOutOfMemoryExhaustedCallback(size_t size)
    194 {
    195     psLogMsg(__func__,PS_LOG_INFO,"Custom MemExhaustedCallback was invoked.");
    196     TPOutOfMemoryExhaustedCallbackCalled = true;
    197     return malloc(1024);
    198187}
    199188
     
    487476}
    488477
    489 long memAllocateCallback(const psMemBlock *ptr)
     478psMemoryId memAllocateCallback(const psMemBlock *ptr)
    490479{
    491480    psLogMsg(__func__,PS_LOG_INFO,"block %d was (re)allocated",ptr->id);
     
    494483}
    495484
    496 long memFreeCallback(const psMemBlock *ptr)
     485psMemoryId memFreeCallback(const psMemBlock *ptr)
    497486{
    498487    psLogMsg(__func__,PS_LOG_INFO,"block %d was freed",ptr->id);
     
    500489    return 1;
    501490}
     491
     492void* TPOutOfMemoryExhaustedCallback(size_t size)
     493{
     494    psLogMsg(__func__,PS_LOG_INFO,"Custom MemExhaustedCallback was invoked.");
     495    exhaustedCallbackCalled++;
     496    return NULL;
     497}
Note: See TracChangeset for help on using the changeset viewer.