mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-23 09:59:54 +00:00
src/strings.c : Minor refactoring. Make sure that the memory allocation
size if always > 0 to avoid undefined behaviour.
This commit is contained in:
parent
34132bf788
commit
23893dc297
@ -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
|
||||
|
@ -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 ;
|
||||
|
Loading…
Reference in New Issue
Block a user