Changeset 11087

Show
Ignore:
Timestamp:
03/26/07 23:55:12 (2 years ago)
Author:
warmerdam
Message:

Fix crash when poGeometry or GetStyleString?() returns null for special
fields in GetFieldAsString?(). (bug #1528).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.4/gdal/ogr/ogrfeature.cpp

    r10646 r11087  
    956956    if (iSpecialField >= 0) 
    957957    { 
    958     // special field value accessors 
     958        // special field value accessors 
    959959        switch (iSpecialField) 
    960960        { 
    961         case SPF_FID: 
     961          case SPF_FID: 
    962962            snprintf( szTempBuffer, TEMP_BUFFER_SIZE, "%ld", GetFID() ); 
    963963            return m_pszTmpFieldValue = CPLStrdup( szTempBuffer ); 
    964         case SPF_OGR_GEOMETRY: 
    965             return poGeometry->getGeometryName(); 
    966         case SPF_OGR_STYLE: 
    967             return GetStyleString(); 
    968         case SPF_OGR_GEOM_WKT: 
    969             { 
    970                 if (poGeometry->exportToWkt( &m_pszTmpFieldValue ) == OGRERR_NONE ) 
    971                     return m_pszTmpFieldValue; 
    972                 else 
    973                     return ""; 
    974             } 
    975         default: 
     964 
     965          case SPF_OGR_GEOMETRY: 
     966            if( poGeometry ) 
     967                return poGeometry->getGeometryName(); 
     968            else 
     969                return ""; 
     970 
     971          case SPF_OGR_STYLE: 
     972            if( GetStyleString() == NULL ) 
     973                return ""; 
     974            else 
     975                return GetStyleString(); 
     976 
     977          case SPF_OGR_GEOM_WKT: 
     978          { 
     979              if( poGeometry == NULL ) 
     980                  return ""; 
     981 
     982              if (poGeometry->exportToWkt( &m_pszTmpFieldValue ) == OGRERR_NONE ) 
     983                  return m_pszTmpFieldValue; 
     984              else 
     985                  return ""; 
     986          } 
     987 
     988          default: 
    976989            return ""; 
    977990        } 
     
    10071020        { 
    10081021            snprintf( szFormat, TEMP_BUFFER_SIZE, "%%%d.%df", 
    1009                      poFDefn->GetWidth(), poFDefn->GetPrecision() ); 
     1022                      poFDefn->GetWidth(), poFDefn->GetPrecision() ); 
    10101023        } 
    10111024        else 
     
    10441057            if( nMinutes == 0 ) 
    10451058                snprintf( szTempBuffer+strlen(szTempBuffer),  
    1046                          TEMP_BUFFER_SIZE, "%02d", nHours ); 
     1059                          TEMP_BUFFER_SIZE, "%02d", nHours ); 
    10471060            else 
    10481061                snprintf( szTempBuffer+strlen(szTempBuffer),  
    1049                          TEMP_BUFFER_SIZE, "%02d%02d", nHours, nMinutes ); 
     1062                          TEMP_BUFFER_SIZE, "%02d%02d", nHours, nMinutes ); 
    10501063        } 
    10511064 
     
    10551068    { 
    10561069        snprintf( szTempBuffer, TEMP_BUFFER_SIZE, "%04d/%02d/%02d", 
    1057                  pauFields[iField].Date.Year, 
    1058                  pauFields[iField].Date.Month, 
    1059                  pauFields[iField].Date.Day ); 
     1070                  pauFields[iField].Date.Year, 
     1071                  pauFields[iField].Date.Month, 
     1072                  pauFields[iField].Date.Day ); 
    10601073 
    10611074        return m_pszTmpFieldValue = CPLStrdup( szTempBuffer ); 
     
    10641077    { 
    10651078        snprintf( szTempBuffer, TEMP_BUFFER_SIZE, "%2d:%02d:%02d",  
    1066                  pauFields[iField].Date.Hour, 
    1067                  pauFields[iField].Date.Minute, 
    1068                  pauFields[iField].Date.Second ); 
     1079                  pauFields[iField].Date.Hour, 
     1080                  pauFields[iField].Date.Minute, 
     1081                  pauFields[iField].Date.Second ); 
    10691082         
    10701083        return m_pszTmpFieldValue = CPLStrdup( szTempBuffer );