Ticket #2810 (closed defect: fixed)
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;
}
