src/strings.c : Minor refactoring. Make sure that the memory allocation

size if always > 0 to avoid undefined behaviour.
This commit is contained in:
Erik de Castro Lopo 2012-03-01 22:08:42 +11:00
parent 34132bf788
commit 23893dc297
2 changed files with 8 additions and 5 deletions

View File

@ -1,3 +1,9 @@
2012-02-01 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/strings.c
Small refactoring. Make sure that the memory allocation size if always > 0
to avoid undefined behaviour.
2012-02-29 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/chunk.c

View File

@ -41,11 +41,6 @@ psf_store_string (SF_PRIVATE *psf, int str_type, const char *str)
str_len = strlen (str) ;
if (psf->strings.storage == NULL)
{ psf->strings.storage_len = 2 * str_len ;
psf->strings.storage = malloc (psf->strings.storage_len) ;
} ;
/* A few extra checks for write mode. */
if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR)
{ if ((psf->strings.flags & SF_STR_ALLOW_START) == 0)
@ -136,6 +131,8 @@ psf_store_string (SF_PRIVATE *psf, int str_type, const char *str)
{ char * temp = psf->strings.storage ;
size_t newlen = 2 * psf->strings.storage_len + str_len ;
newlen = newlen < 256 ? 256 : newlen ;
if ((psf->strings.storage = realloc (temp, newlen)) == NULL)
{ psf->strings.storage = temp ;
return SFE_MALLOC_FAILED ;