src/ : Fix a bunch of valgrind errors.

This commit is contained in:
Erik de Castro Lopo 2012-03-14 20:37:11 +11:00
parent 495c2877e1
commit fcd0e6a21b
7 changed files with 35 additions and 32 deletions

View File

@ -12,6 +12,9 @@
* src/test_strncpy_crlf.c
Fix minor error in test. Thanks Kao Dome.
* src/common.h src/*.c
Fix a bunch of valgrind errors.
2012-02-13 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/sndfile.c

View File

@ -1482,24 +1482,24 @@ aiff_write_strings (SF_PRIVATE *psf, int location)
switch (psf->strings.data [k].type)
{ case SF_STR_SOFTWARE :
slen = strlen (psf->strings.data [k].str) ;
psf_binheader_writef (psf, "Em4mb", APPL_MARKER, slen + 4, m3ga_MARKER, psf->strings.data [k].str, make_size_t (slen + (slen & 1))) ;
slen = strlen (psf->strings.storage + psf->strings.data [k].offset) ;
psf_binheader_writef (psf, "Em4mb", APPL_MARKER, slen + 4, m3ga_MARKER, psf->strings.storage + psf->strings.data [k].offset, make_size_t (slen + (slen & 1))) ;
break ;
case SF_STR_TITLE :
psf_binheader_writef (psf, "EmS", NAME_MARKER, psf->strings.data [k].str) ;
psf_binheader_writef (psf, "EmS", NAME_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
break ;
case SF_STR_COPYRIGHT :
psf_binheader_writef (psf, "EmS", c_MARKER, psf->strings.data [k].str) ;
psf_binheader_writef (psf, "EmS", c_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
break ;
case SF_STR_ARTIST :
psf_binheader_writef (psf, "EmS", AUTH_MARKER, psf->strings.data [k].str) ;
psf_binheader_writef (psf, "EmS", AUTH_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
break ;
case SF_STR_COMMENT :
psf_binheader_writef (psf, "EmS", ANNO_MARKER, psf->strings.data [k].str) ;
psf_binheader_writef (psf, "EmS", ANNO_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
break ;
/*

View File

@ -229,7 +229,7 @@ peak_info_calloc (int channels)
typedef struct
{ int type ;
int flags ;
char *str ;
size_t offset ;
} STR_DATA ;
typedef struct
@ -379,7 +379,7 @@ typedef struct sf_private_tag
{ STR_DATA data [SF_MAX_STRINGS] ;
char *storage ;
size_t storage_len ;
uint32_t str_last ;
size_t storage_used ;
uint32_t flags ;
} strings ;

View File

@ -585,7 +585,7 @@ flac_write_strings (SF_PRIVATE *psf, FLAC_PRIVATE* pflac)
continue ;
} ;
value = psf->strings.data [k].str ;
value = psf->strings.storage + psf->strings.data [k].offset ;
FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair (&entry, key, value) ;
FLAC__metadata_object_vorbiscomment_append_comment (pflac->metadata, entry, /* copy */ SF_FALSE) ;

View File

@ -382,7 +382,7 @@ vorbis_write_header (SF_PRIVATE *psf, int UNUSED (calc_length))
default : continue ;
} ;
vorbis_comment_add_tag (&vdata->vcomment, name, psf->strings.data [k].str) ;
vorbis_comment_add_tag (&vdata->vcomment, name, psf->strings.storage + psf->strings.data [k].offset) ;
} ;
/* set up the analysis state and auxiliary encoding storage */

View File

@ -74,19 +74,19 @@ psf_store_string (SF_PRIVATE *psf, int str_type, const char *str)
if (k >= SF_MAX_STRINGS)
return SFE_STR_MAX_COUNT ;
if (k == 0 && psf->strings.str_last != 0)
{ psf_log_printf (psf, "SFE_STR_WEIRD : k == 0 && psf->strings.str_last != 0\n") ;
if (k == 0 && psf->strings.storage_used != 0)
{ psf_log_printf (psf, "SFE_STR_WEIRD : k == 0 && psf->strings.storage_used != 0\n") ;
return SFE_STR_WEIRD ;
} ;
if (k != 0 && psf->strings.str_last == 0)
{ psf_log_printf (psf, "SFE_STR_WEIRD : k != 0 && psf->strings.str_last == 0\n") ;
if (k != 0 && psf->strings.storage_used == 0)
{ psf_log_printf (psf, "SFE_STR_WEIRD : k != 0 && psf->strings.storage_used == 0\n") ;
return SFE_STR_WEIRD ;
} ;
/* Special case for the first string. */
if (k == 0)
psf->strings.str_last = 0 ;
psf->strings.storage_used = 0 ;
switch (str_type)
{ case SF_STR_SOFTWARE :
@ -125,9 +125,10 @@ psf_store_string (SF_PRIVATE *psf, int str_type, const char *str)
return SFE_STR_BAD_TYPE ;
} ;
str_len = strlen (str) ;
/* Plus one to catch string terminator. */
str_len = strlen (str) + 1 ;
if (psf->strings.str_last + str_len + 2 > psf->strings.storage_len)
if (psf->strings.storage_used + str_len + 1 > psf->strings.storage_len)
{ char * temp = psf->strings.storage ;
size_t newlen = 2 * psf->strings.storage_len + str_len ;
@ -142,20 +143,19 @@ psf_store_string (SF_PRIVATE *psf, int str_type, const char *str)
} ;
psf->strings.data [k].type = str_type ;
psf->strings.data [k].str = psf->strings.storage + psf->strings.str_last ;
psf->strings.data [k].offset = psf->strings.storage_used ;
psf->strings.data [k].flags = str_flags ;
memcpy (psf->strings.storage + psf->strings.str_last, str, str_len + 1) ;
/* Plus one to catch string terminator. */
psf->strings.str_last += str_len + 1 ;
memcpy (psf->strings.storage + psf->strings.storage_used, str, str_len) ;
psf->strings.storage_used += str_len ;
psf->strings.flags |= str_flags ;
#if STRINGS_DEBUG
psf_log_printf (psf, "str_storage : %p\n", psf->strings.storage) ;
psf_log_printf (psf, "str_last : %u\n", psf->strings.str_last) ;
psf_log_printf (psf, "used : %d\n", psf->strings.str_last) ;
psf_log_printf (psf, "remaining : %d\n", psf->strings.storage_len - psf->strings.str_last ;
psf_log_printf (psf, "storage_used : %u\n", psf->strings.storage_used) ;
psf_log_printf (psf, "used : %d\n", psf->strings.storage_used) ;
psf_log_printf (psf, "remaining : %d\n", psf->strings.storage_len - psf->strings.storage_used ;
hexdump (psf->strings.storage, 300) ;
#endif
@ -177,7 +177,7 @@ psf_get_string (SF_PRIVATE *psf, int str_type)
for (k = 0 ; k < SF_MAX_STRINGS ; k++)
if (str_type == psf->strings.data [k].type)
return psf->strings.data [k].str ;
return psf->strings.storage + psf->strings.data [k].offset ;
return NULL ;
} /* psf_get_string */

View File

@ -1209,31 +1209,31 @@ wav_write_strings (SF_PRIVATE *psf, int location)
switch (psf->strings.data [k].type)
{ case SF_STR_SOFTWARE :
psf_binheader_writef (psf, "ms", ISFT_MARKER, psf->strings.data [k].str) ;
psf_binheader_writef (psf, "ms", ISFT_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
break ;
case SF_STR_TITLE :
psf_binheader_writef (psf, "ms", INAM_MARKER, psf->strings.data [k].str) ;
psf_binheader_writef (psf, "ms", INAM_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
break ;
case SF_STR_COPYRIGHT :
psf_binheader_writef (psf, "ms", ICOP_MARKER, psf->strings.data [k].str) ;
psf_binheader_writef (psf, "ms", ICOP_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
break ;
case SF_STR_ARTIST :
psf_binheader_writef (psf, "ms", IART_MARKER, psf->strings.data [k].str) ;
psf_binheader_writef (psf, "ms", IART_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
break ;
case SF_STR_COMMENT :
psf_binheader_writef (psf, "ms", ICMT_MARKER, psf->strings.data [k].str) ;
psf_binheader_writef (psf, "ms", ICMT_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
break ;
case SF_STR_DATE :
psf_binheader_writef (psf, "ms", ICRD_MARKER, psf->strings.data [k].str) ;
psf_binheader_writef (psf, "ms", ICRD_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
break ;
case SF_STR_GENRE :
psf_binheader_writef (psf, "ms", IGNR_MARKER, psf->strings.data [k].str) ;
psf_binheader_writef (psf, "ms", IGNR_MARKER, psf->strings.storage + psf->strings.data [k].offset) ;
break ;
default :