Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#5314 closed defect (fixed)

Returning empty const char* from CPLString

Reported by: bishop Owned by: warmerdam
Priority: normal Milestone:
Component: OGR_SF Version: svn-trunk
Severity: normal Keywords: CPLString s57 const char*
Cc:

Description

The GDAL compiled with VS2010-VS2013 in s57 driver loose all additional fields values. But the same code compiled with gcc or previous VS works fine. The root of problems is in code (ogr\ogrsf_frmts\s57\s57reader.cpp:932):

const char *pszAcronym = poRegistrar->GetAttrAcronym(nAttrId);
    iField = poFeature->GetDefnRef()->GetFieldIndex(pszAcronym);

The pszAcronym always empty.

The problem comes from this function (ogr\ogrsf_frmts\s57\s57.h:140):

const char *GetAttrAcronym( int i )
        { return GetAttrInfo(i) == NULL ? NULL : aoAttrInfos[i]->osAcronym; }

It seems to me that during execution this function we have situation where the c_str() result becomes invalid (the std::string is destroyed or a non-const member function of the string is called).

The c_str() method of std::string not returning the pointer, but construct new zero ended const char* managed by std::string (maybe this is specific to VS2010-VS2013). This const char* cleared after some call to std::string or CPLString and we got empty (cleared) const char *pszAcronym.

I think the VS2010-VS2013 compiler do this in getter by index, operator const char* or the whole GetAttrInfo(i) == NULL ? NULL : aoAttrInfos[i]->osAcronym.

Maybe MS change the order parameter calculation or optimization or maybe const (operator const char* (void) const) in non const (const char *GetAttrAcronym( int i )) function VS2010-VS2013 specific behaviour.

Change History (2)

comment:1 by bishop, 10 years ago

Resolution: fixed
Status: newclosed

Fix in r26689.

comment:2 by Even Rouault, 10 years ago

Thanks. It did indeed fix the failure on ogr_s57_6 test on the release-1600-XXX builds at http://gisinternals.com/sdk/

Note: See TracTickets for help on using tickets.