Ticket #2134: gdal-1.5.0-bug-cpl_list.patch

File gdal-1.5.0-bug-cpl_list.patch, 1.9 kB (added by dgrichard, 4 months ago)

cpl_list bug fixe proposal

  • gdal-1.5.0/port/cpl_list.cpp

    old new  
    111111        psNew->pData = pData; 
    112112 
    113113        psCurrent = psList; 
    114         for ( i = 0; i < nPosition - 1; i++ ) 
    115             psCurrent = psCurrent->psNext; 
    116         psNew->psNext = psCurrent->psNext; 
    117         psCurrent->psNext = psNew; 
     114        if( nPosition > 0) 
     115        { 
     116            for ( i = 0; i < nPosition - 1; i++ ) 
     117                psCurrent = psCurrent->psNext; 
     118            psNew->psNext = psCurrent->psNext; 
     119            psCurrent->psNext = psNew; 
     120        } 
     121        else 
     122        { 
     123            if ( psList ) 
     124            { 
     125                psNew->pData= psList->pData; 
     126                psNew->psNext= psList->psNext; 
     127                psList->pData= pData; 
     128                psList->psNext= psNew; 
     129            } 
     130            else 
     131            { 
     132                psList= psNew; 
     133                psNew->psNext= NULL; 
     134            } 
     135        } 
    118136    } 
    119137 
    120138    return psList; 
     
    205223/************************************************************************/ 
    206224 
    207225/** 
    208  * Remone the element from the specified position (zero based) in a list. Data 
     226 * Revone the element from the specified position (zero based) in a list. Data 
    209227 * object contained in removed element must be freed by the caller first. 
    210228 *  
    211229 * @param psList pointer to list head. 
     
    225243        return psList;      /* Nothing to do!*/ 
    226244 
    227245    psCurrent = psList; 
    228     for ( i = 0; i < nPosition - 1; i++ ) 
    229         psCurrent = psCurrent->psNext; 
     246    if( nPosition > 0 ) 
     247        for ( i = 0; i < nPosition - 1; i++ ) 
     248            psCurrent = psCurrent->psNext; 
    230249    psRemoved = psCurrent->psNext; 
    231250    psCurrent->psNext = psRemoved->psNext; 
    232251    CPLFree( psRemoved );