Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHPOpenLL(): avoid GDAL specific error message when .shx is missing #130

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions shpopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
#endif
#endif

/* Allows customization of the message in vendored builds (such as GDAL) */
#ifndef SHP_RESTORE_SHX_HINT_MESSAGE
#define SHP_RESTORE_SHX_HINT_MESSAGE \
" Use SHPRestoreSHX() to restore or create it."
#endif

/************************************************************************/
/* SHPWriteHeader() */
/* */
Expand Down Expand Up @@ -324,14 +330,14 @@ SHPHandle SHPAPI_CALL SHPOpenLL(const char *pszLayer, const char *pszAccess,

if (psSHP->fpSHX == SHPLIB_NULLPTR)
{
const size_t nMessageLen = strlen(pszFullname) * 2 + 256;
const size_t nMessageLen =
64 + strlen(pszFullname) * 2 + strlen(SHP_RESTORE_SHX_HINT_MESSAGE);
char *pszMessage = STATIC_CAST(char *, malloc(nMessageLen));
pszFullname[nLenWithoutExtension] = 0;
snprintf(pszMessage, nMessageLen,
"Unable to open %s.shx or %s.SHX. "
"Set SHAPE_RESTORE_SHX config option to YES to restore or "
"create it.",
pszFullname, pszFullname);
snprintf(
pszMessage, nMessageLen,
"Unable to open %s.shx or %s.SHX." SHP_RESTORE_SHX_HINT_MESSAGE,
pszFullname, pszFullname);
psHooks->Error(pszMessage);
free(pszMessage);

Expand Down