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

Use strcpy rather than strdup #5610

Merged
merged 4 commits into from Jun 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 15 additions & 11 deletions mapstring.c
Expand Up @@ -2103,22 +2103,26 @@ int msStringIsInteger(const char *string)

/* Safe version of msStrdup(). This function is taken from gdal/cpl. */

char *msStrdup( const char * pszString )
char *msStrdup(const char * pszString)
{
char *pszReturn;
size_t nStringLength;
char *pszReturn;

if( pszString == NULL )
pszString = "";
if (pszString == NULL)
pszString = "";

pszReturn = strdup( pszString );
nStringLength = strlen(pszString) + 1; /* null terminated byte */
pszReturn = malloc(nStringLength);

if( pszReturn == NULL ) {
fprintf(stderr, "msSmallMsStrdup(): Out of memory allocating %ld bytes.\n",
(long) strlen(pszString) );
exit(1);
}
if (pszReturn == NULL) {
fprintf(stderr, "msSmallMalloc(): Out of memory allocating %ld bytes.\n",
(long)strlen(pszString));
exit(1);
}

memcpy(pszReturn, pszString, nStringLength);

return( pszReturn );
return pszReturn;
}


Expand Down