From: <sba...@us...> - 2021-03-13 22:45:57
|
This is an automated email from the git hooks/post-receive-user script. sbaldovi pushed a commit to branch master in repository libspectrum. View the commit online: https://sourceforge.net/p/fuse-emulator/libspectrum/ci/3926b3d5f2eb28de1909b09b4513e15c8d791e53/ commit 3926b3d5f2eb28de1909b09b4513e15c8d791e53 Author: Sergio Baldoví <ser...@gm...> AuthorDate: Sat Mar 13 13:05:27 2021 +0100 Use libspectrum's memory management instead of strdup As we usually use libspectrum_free() --- internals.h | 3 +++ libspectrum.c | 2 +- utilities.c | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/internals.h b/internals.h index 2d474be..67b3ea8 100644 --- a/internals.h +++ b/internals.h @@ -362,6 +362,9 @@ libspectrum_bits_to_bytes( size_t bits ); extern const int LIBSPECTRUM_BITS_IN_BYTE; +char* +libspectrum_safe_strdup( const char *src ); + /* glib replacement functions */ #ifndef HAVE_LIB_GLIB /* Only if we are using glib replacement */ diff --git a/libspectrum.c b/libspectrum.c index 486bcde..55ba4aa 100644 --- a/libspectrum.c +++ b/libspectrum.c @@ -776,7 +776,7 @@ libspectrum_uncompress_file( unsigned char **new_buffer, size_t *new_length, } if( new_filename && old_filename ) { - *new_filename = strdup( old_filename ); + *new_filename = libspectrum_safe_strdup( old_filename ); if( !*new_filename ) { libspectrum_print_error( LIBSPECTRUM_ERROR_MEMORY, "out of memory at %s:%d", __FILE__, __LINE__ ); diff --git a/utilities.c b/utilities.c index 09d5d43..9555154 100644 --- a/utilities.c +++ b/utilities.c @@ -64,3 +64,18 @@ libspectrum_bits_to_bytes( size_t bits ) { return ( bits + LIBSPECTRUM_BITS_IN_BYTE - 1 ) / LIBSPECTRUM_BITS_IN_BYTE; } + +char* +libspectrum_safe_strdup( const char *src ) +{ + size_t length; + char *dest = NULL; + + if( src ) { + length = strlen( src ) + 1; + dest = libspectrum_new( char, length ); + memcpy( dest, src, length ); + } + + return dest; +} |