Skip to content

Commit

Permalink
SPEX: Allocate enough memory for NULL terminator.
Browse files Browse the repository at this point in the history
Fixes #847.

Thank you to Sébastien Villemot for pointing out the fix.
  • Loading branch information
mmuetzel committed Jul 7, 2024
1 parent 448bc50 commit dfc51ea
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions SPEX/Python/SPEXpy/Source/spex_python_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ SPEX_info spex_python

//--------------------------------------------------------------------------
// solve Ax=b
//-------------------------------------------------------------------------
//--------------------------------------------------------------------------
switch(algorithm)
{
case 1:
Expand All @@ -130,7 +130,7 @@ SPEX_info spex_python

//--------------------------------------------------------------------------
// Return output as desired type
//-----------------------------------------------------------------------
//--------------------------------------------------------------------------
if(charOut)
{
//solution as string
Expand All @@ -143,12 +143,12 @@ SPEX_info spex_python
printf("error converting x to string");
}
//check string size
int sizeStr;
sizeStr=strlen(s);
size_t sizeStr;
sizeStr = strlen(s);
//allocate sol_char[i]
sol_void[i] = (void*) malloc (sizeStr*sizeof(char));
sol_void[i] = malloc (sizeStr + 1); // +1 for NULL terminator
//copy s into sol_char[i]
strcpy(sol_void[i],s);
strcpy(sol_void[i], s);
}
}
else
Expand Down

0 comments on commit dfc51ea

Please sign in to comment.