Skip to content

Commit

Permalink
Merge pull request #10633 from rouault/RATValuesIONumPyWrite_warning_fix
Browse files Browse the repository at this point in the history
Python bindings: fix warning about mismatch int vs npy_intp in RATValuesIONumPyWrite()
  • Loading branch information
rouault authored Aug 25, 2024
2 parents 30eaea3 + e33dbc6 commit cd70a53
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions swig/include/gdal_array.i
Original file line number Diff line number Diff line change
Expand Up @@ -2225,16 +2225,22 @@ PyObject* _RecordBatchAsNumpy(VoidPtrAsLong recordBatchPtr,
}
else if( nType == NPY_STRING )
{
// have to convert array of strings to a char **
char **papszStringData = (char**)CPLCalloc(sizeof(char*), nLength);

// max size of string
int nMaxLen = PyArray_ITEMSIZE(psArray);
char *pszBuffer = (char*)CPLMalloc((nMaxLen+1) * sizeof(char));
const size_t nMaxLen = PyArray_ITEMSIZE(psArray);
char *pszBuffer = (char*)VSIMalloc(nMaxLen+1);
if (!pszBuffer)
{
CPLError( CE_Failure, CPLE_OutOfMemory,
"Out of memory in RATValuesIONumPyWrite()" );
return CE_Failure;
}
// make sure there is a null char on the end
// as there won't be if this string is the maximum size
pszBuffer[nMaxLen] = '\0';

// have to convert array of strings to a char **
char **papszStringData = (char**)CPLCalloc(sizeof(char*), nLength);

// we can't just use the memory location in the array
// since long strings won't be null terminated
for( int i = 0; i < nLength; i++ )
Expand Down

0 comments on commit cd70a53

Please sign in to comment.