Ticket #2810 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

AddStyle crashes

Reported by: ftrastour Owned by: rouault
Priority: normal Milestone: 1.5.5
Component: default Version: unspecified
Severity: normal Keywords:
Cc:

Description

This bug was already signaled in ticket #2531; the summary of this ticket is good but not the content...

AddStyle? inconsistently uses CPLString().Printf() and causes a crash.

Here is a fix :

GBool OGRStyleTable::AddStyle?(const char *pszName, const char *pszStyleString) {

int nPos;

if (pszName && pszStyleString) {

if ((nPos = IsExist?(pszName)) != -1)

return FALSE;

m_papszStyleTable = CSLAddString(m_papszStyleTable,

CPLString().Printf("%s:%s",pszName,pszStyleString));

return TRUE;

} return FALSE;

}

There is another potential wrong usage of CPLString().Printf in OGRStyleTable::IsExist?.

A possible fix :

int OGRStyleTable::IsExist?(const char *pszName) {

int i;

if (pszName == NULL)

return -1;

const char *pszNewString = CPLSPrintf("%s:",pszName);

for (i=0;i<CSLCount(m_papszStyleTable);i++) {

if (strstr(m_papszStyleTable[i],pszNewString) != NULL)

return i;

} return -1;

}

Change History

Changed 3 years ago by rouault

  • owner changed from warmerdam to rouault
  • status changed from new to assigned

Changed 3 years ago by rouault

  • status changed from assigned to closed
  • resolution set to fixed
  • milestone set to 1.5.5

Thanks for the report and fix!

Applied in trunk (r16196), branches/1.6 (r16197) and branches/1.5 (r16198).

Note: See TracTickets for help on using tickets.