From: <fr...@us...> - 2014-12-30 11:29:54
|
Revision: 5106 http://sourceforge.net/p/fuse-emulator/code/5106 Author: fredm Date: 2014-12-30 11:29:52 +0000 (Tue, 30 Dec 2014) Log Message: ----------- Select glibtoolize where required (Sergio via fuse). Modified Paths: -------------- trunk/libspectrum/autogen.sh trunk/libspectrum/hacking/ChangeLog Modified: trunk/libspectrum/autogen.sh =================================================================== --- trunk/libspectrum/autogen.sh 2014-12-29 13:08:38 UTC (rev 5105) +++ trunk/libspectrum/autogen.sh 2014-12-30 11:29:52 UTC (rev 5106) @@ -28,6 +28,9 @@ aclocal -I m4 autoheader -libtoolize --automake +# Mac OS X: Use glibtoolize instead +(glibtoolize --version) < /dev/null > /dev/null 2>&1 && LIBTOOLIZE=glibtoolize \ + || LIBTOOLIZE=libtoolize +$LIBTOOLIZE --automake automake --add-missing autoconf Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2014-12-29 13:08:38 UTC (rev 5105) +++ trunk/libspectrum/hacking/ChangeLog 2014-12-30 11:29:52 UTC (rev 5106) @@ -964,3 +964,4 @@ Lee Tonks) (Fred). 20141230 szx.c: guard against passing a NULL pointer to memcpy in write_if1_chunk() (thanks, clang static analyser) (Fred). +20141230 autogen.sh: select glibtoolize where required (Sergio via fuse). This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sba...@us...> - 2015-01-07 21:29:25
|
Revision: 5112 http://sourceforge.net/p/fuse-emulator/code/5112 Author: sbaldovi Date: 2015-01-07 21:29:18 +0000 (Wed, 07 Jan 2015) Log Message: ----------- Rewrite some conditions for RZX finalisation in a more logical way. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/rzx.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-01-07 21:17:59 UTC (rev 5111) +++ trunk/libspectrum/hacking/ChangeLog 2015-01-07 21:29:18 UTC (rev 5112) @@ -965,3 +965,5 @@ 20141230 szx.c: guard against passing a NULL pointer to memcpy in write_if1_chunk() (thanks, clang static analyser) (Fred). 20141230 autogen.sh: select glibtoolize where required (Sergio via fuse). +20150107 rzx.c: rewrite some conditions for RZX finalisation in a more logical + way (thanks, clang static analyser) (Sergio). Modified: trunk/libspectrum/rzx.c =================================================================== --- trunk/libspectrum/rzx.c 2015-01-07 21:17:59 UTC (rev 5111) +++ trunk/libspectrum/rzx.c 2015-01-07 21:29:18 UTC (rev 5112) @@ -1781,9 +1781,11 @@ if( block->type == LIBSPECTRUM_RZX_INPUT_BLOCK ) { next_item = list->next; - next_block = ( next_item )? next_item->data : NULL; + if( !next_item ) break; - if( next_block && next_block->type == LIBSPECTRUM_RZX_INPUT_BLOCK ) { + next_block = next_item->data; + + if( next_block->type == LIBSPECTRUM_RZX_INPUT_BLOCK ) { error = input_block_merge( &( block->types.input ), &( next_block->types.input ) ); if( error ) return error; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sba...@us...> - 2015-01-07 21:37:26
|
Revision: 5113 http://sourceforge.net/p/fuse-emulator/code/5113 Author: sbaldovi Date: 2015-01-07 21:37:19 +0000 (Wed, 07 Jan 2015) Log Message: ----------- Remove "Function call argument is an uninitialized value" warning. There's no chance that it is, but clang doesn't realise that. Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/test/test.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-01-07 21:29:18 UTC (rev 5112) +++ trunk/libspectrum/hacking/ChangeLog 2015-01-07 21:37:19 UTC (rev 5113) @@ -967,3 +967,6 @@ 20141230 autogen.sh: select glibtoolize where required (Sergio via fuse). 20150107 rzx.c: rewrite some conditions for RZX finalisation in a more logical way (thanks, clang static analyser) (Sergio). +20150107 test/test.c: remove "Function call argument is an uninitialized value" + warning. There's no chance that it is, but clang doesn't realise that + (Sergio). Modified: trunk/libspectrum/test/test.c =================================================================== --- trunk/libspectrum/test/test.c 2015-01-07 21:29:18 UTC (rev 5112) +++ trunk/libspectrum/test/test.c 2015-01-07 21:37:19 UTC (rev 5113) @@ -497,8 +497,8 @@ test_24( void ) { const char *filename = DYNAMIC_TEST_PATH( "complete-tzx.tzx" ); - libspectrum_byte *buffer; - size_t filesize; + libspectrum_byte *buffer = NULL; + size_t filesize = 0; libspectrum_tape *tape; libspectrum_tape_iterator it; libspectrum_tape_block *block; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-02-25 22:31:12
|
Revision: 5115 http://sourceforge.net/p/fuse-emulator/code/5115 Author: zubzero Date: 2015-02-25 22:31:10 +0000 (Wed, 25 Feb 2015) Log Message: ----------- Avoid (undefined) reliance on pointer overflow in buffer length checks Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/pzx_read.c trunk/libspectrum/szx.c trunk/libspectrum/tzx_read.c trunk/libspectrum/warajevo_read.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-02-20 23:17:44 UTC (rev 5114) +++ trunk/libspectrum/hacking/ChangeLog 2015-02-25 22:31:10 UTC (rev 5115) @@ -970,3 +970,5 @@ 20150107 test/test.c: remove "Function call argument is an uninitialized value" warning. There's no chance that it is, but clang doesn't realise that (Sergio). +20150225 pzx_read.c,szx.c,tzx_read.c,warajevo_read.c: avoid (undefined) reliance + on pointer overflow in buffer length checks (Stuart). Modified: trunk/libspectrum/pzx_read.c =================================================================== --- trunk/libspectrum/pzx_read.c 2015-02-20 23:17:44 UTC (rev 5114) +++ trunk/libspectrum/pzx_read.c 2015-02-25 22:31:10 UTC (rev 5115) @@ -548,7 +548,7 @@ error = read_block_header( id, &data_length, buffer, end ); if( error ) return error; - if( *buffer + data_length > end || *buffer + data_length < *buffer ) { + if( end - *buffer < data_length ) { libspectrum_print_error( LIBSPECTRUM_ERROR_CORRUPT, "read_block: block length goes beyond end of file" Modified: trunk/libspectrum/szx.c =================================================================== --- trunk/libspectrum/szx.c 2015-02-20 23:17:44 UTC (rev 5114) +++ trunk/libspectrum/szx.c 2015-02-25 22:31:10 UTC (rev 5115) @@ -2246,7 +2246,7 @@ error = read_chunk_header( id, &data_length, buffer, end ); if( error ) return error; - if( *buffer + data_length > end || *buffer + data_length < *buffer ) { + if( end - *buffer < data_length ) { libspectrum_print_error( LIBSPECTRUM_ERROR_CORRUPT, "szx_read_chunk: chunk length goes beyond end of file" Modified: trunk/libspectrum/tzx_read.c =================================================================== --- trunk/libspectrum/tzx_read.c 2015-02-20 23:17:44 UTC (rev 5114) +++ trunk/libspectrum/tzx_read.c 2015-02-25 22:31:10 UTC (rev 5115) @@ -604,7 +604,7 @@ data = libspectrum_malloc( data_size ); - if( *ptr + data_size > end || *ptr + data_size < *ptr ) { + if( end - (*ptr) < data_size ) { libspectrum_free( data ); libspectrum_tape_block_free( block ); libspectrum_print_error( LIBSPECTRUM_ERROR_CORRUPT, Modified: trunk/libspectrum/warajevo_read.c =================================================================== --- trunk/libspectrum/warajevo_read.c 2015-02-20 23:17:44 UTC (rev 5114) +++ trunk/libspectrum/warajevo_read.c 2015-02-25 22:31:10 UTC (rev 5115) @@ -211,9 +211,8 @@ int error; libspectrum_dword next_block; - /* Check we have enough data, and check for pointer wrap */ - if( buffer + 8 + *offset > end || buffer + *offset < buffer || - buffer + 8 + *offset < buffer ) { + /* Check we have enough data */ + if( end - buffer < *offset || end - buffer - *offset < 8 ) { libspectrum_print_error( LIBSPECTRUM_ERROR_CORRUPT, "libspectrum_warajevo_read: not enough data in buffer" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-02 12:10:33
|
Revision: 5118 http://sourceforge.net/p/fuse-emulator/code/5118 Author: zubzero Date: 2015-03-02 12:10:25 +0000 (Mon, 02 Mar 2015) Log Message: ----------- Add and use ARRAY_SIZE macro Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/internals.h trunk/libspectrum/pzx_read.c trunk/libspectrum/szx.c trunk/libspectrum/test/test.c trunk/libspectrum/zxs.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-01 11:25:31 UTC (rev 5117) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-02 12:10:25 UTC (rev 5118) @@ -972,3 +972,5 @@ (Sergio). 20150225 pzx_read.c,szx.c,tzx_read.c,warajevo_read.c: avoid (undefined) reliance on pointer overflow in buffer length checks (Stuart). +20150302 internals.h,pzx_read.c,szx.c,test/test.c,zxs.c: add and use ARRAY_SIZE + macro (Stuart). Modified: trunk/libspectrum/internals.h =================================================================== --- trunk/libspectrum/internals.h 2015-03-01 11:25:31 UTC (rev 5117) +++ trunk/libspectrum/internals.h 2015-03-02 12:10:25 UTC (rev 5118) @@ -51,6 +51,32 @@ #endif /* _MSC_VER > 1200 */ #endif /* #ifdef _MSC_VER */ +#if defined(__GNUC__) && defined(__GNUC_MINOR__) + #define GNUC_VERSION \ + (__GNUC__ << 16) + __GNUC_MINOR__ + #define GNUC_PREREQ(maj, min) \ + (GNUC_VERSION >= ((maj) << 16) + (min)) +#else + #define GNUC_PREREQ(maj, min) 0 +#endif + +#define BUILD_BUG_ON_ZERO(e) \ + (sizeof(struct { int:-!!(e) * 1234; })) + +#if GNUC_PREREQ(3, 1) + #define SAME_TYPE(a, b) \ + __builtin_types_compatible_p(typeof(a), typeof(b)) + #define MUST_BE_ARRAY(a) \ + BUILD_BUG_ON_ZERO(SAME_TYPE((a), &(*a))) +#else + #define MUST_BE_ARRAY(a) \ + BUILD_BUG_ON_ZERO(sizeof(a) % sizeof(*a)) +#endif + +#define ARRAY_SIZE(a) ( \ + (sizeof(a) / sizeof(*a)) \ + + MUST_BE_ARRAY(a)) + /* VC6 lacks M_LN2, and VS2003+ require _USE_MATH_DEFINES defined before math.h */ #ifndef M_LN2 Modified: trunk/libspectrum/pzx_read.c =================================================================== --- trunk/libspectrum/pzx_read.c 2015-03-01 11:25:31 UTC (rev 5117) +++ trunk/libspectrum/pzx_read.c 2015-03-02 12:10:25 UTC (rev 5118) @@ -69,9 +69,6 @@ }; -static size_t info_ids_count = - sizeof( info_ids ) / sizeof( struct info_t ); - #define PZX_PULSE "PULS" #define PZX_DATA "DATA" @@ -118,7 +115,7 @@ static int get_id_byte( char *info_tag ) { struct info_t *info = - (struct info_t*)bsearch( info_tag, info_ids, info_ids_count, + (struct info_t*)bsearch( info_tag, info_ids, ARRAY_SIZE( info_ids ), sizeof( struct info_t ), info_t_compar ); return info == NULL ? -1 : info->archive_info_id; } @@ -514,9 +511,6 @@ }; -static size_t read_blocks_count = - sizeof( read_blocks ) / sizeof( struct read_block_t ); - static libspectrum_error read_block_header( char *id, libspectrum_dword *data_length, const libspectrum_byte **buffer, @@ -558,7 +552,7 @@ done = 0; - for( i = 0; !done && i < read_blocks_count; i++ ) { + for( i = 0; !done && i < ARRAY_SIZE( read_blocks ); i++ ) { if( !memcmp( id, read_blocks[i].id, 4 ) ) { error = read_blocks[i].function( tape, buffer, end, data_length, ctx ); Modified: trunk/libspectrum/szx.c =================================================================== --- trunk/libspectrum/szx.c 2015-03-01 11:25:31 UTC (rev 5117) +++ trunk/libspectrum/szx.c 2015-03-02 12:10:25 UTC (rev 5118) @@ -2211,9 +2211,6 @@ }; -static size_t read_chunks_count = - sizeof( read_chunks ) / sizeof( struct read_chunk_t ); - static libspectrum_error read_chunk_header( char *id, libspectrum_dword *data_length, const libspectrum_byte **buffer, @@ -2256,7 +2253,7 @@ done = 0; - for( i = 0; !done && i < read_chunks_count; i++ ) { + for( i = 0; !done && i < ARRAY_SIZE( read_chunks ); i++ ) { if( !memcmp( id, read_chunks[i].id, 4 ) ) { error = read_chunks[i].function( snap, version, buffer, end, Modified: trunk/libspectrum/test/test.c =================================================================== --- trunk/libspectrum/test/test.c 2015-03-01 11:25:31 UTC (rev 5117) +++ trunk/libspectrum/test/test.c 2015-03-02 12:10:25 UTC (rev 5118) @@ -6,6 +6,7 @@ #include <sys/types.h> #include <unistd.h> +#include "internals.h" #include "test.h" const char *progname; @@ -770,7 +771,7 @@ { test_27, "Reading old SZX file", 0 }, }; -static size_t test_count = sizeof( tests ) / sizeof( tests[0] ); +static size_t test_count = ARRAY_SIZE( tests ); static void parse_test_specs( char **specs, int count ) Modified: trunk/libspectrum/zxs.c =================================================================== --- trunk/libspectrum/zxs.c 2015-03-01 11:25:31 UTC (rev 5117) +++ trunk/libspectrum/zxs.c 2015-03-02 12:10:25 UTC (rev 5118) @@ -427,9 +427,6 @@ }; -static size_t read_chunks_count = - sizeof( read_chunks ) / sizeof( struct read_chunk_t ); - static libspectrum_error read_chunk_header( char *id, libspectrum_dword *data_length, const libspectrum_byte **buffer, @@ -472,7 +469,7 @@ done = 0; - for( i = 0; !done && i < read_chunks_count; i++ ) { + for( i = 0; !done && i < ARRAY_SIZE( read_chunks ); i++ ) { if( !strcmp( id, read_chunks[i].id ) ) { error = read_chunks[i].function( snap, &compression, buffer, end, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-02 12:28:20
|
Revision: 5120 http://sourceforge.net/p/fuse-emulator/code/5120 Author: zubzero Date: 2015-03-02 12:28:08 +0000 (Mon, 02 Mar 2015) Log Message: ----------- Add libspectrum_{new,new0,renew}() macros Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/libspectrum.h.in Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-02 12:17:38 UTC (rev 5119) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-02 12:28:08 UTC (rev 5120) @@ -974,3 +974,4 @@ on pointer overflow in buffer length checks (Stuart). 20150302 internals.h,pzx_read.c,szx.c,test/test.c,zxs.c: add and use ARRAY_SIZE macro (Stuart). +20150302 libspectrum.h.in: add libspectrum_{new,new0,renew}() macros (Stuart). Modified: trunk/libspectrum/libspectrum.h.in =================================================================== --- trunk/libspectrum/libspectrum.h.in 2015-03-02 12:17:38 UTC (rev 5119) +++ trunk/libspectrum/libspectrum.h.in 2015-03-02 12:28:08 UTC (rev 5120) @@ -149,6 +149,15 @@ WIN32_DLL void libspectrum_mem_set_vtable( libspectrum_mem_vtable_t *table ); +#define libspectrum_new( type, count ) \ + ( ( type * ) libspectrum_malloc( sizeof( type ) * (count) ) ) + +#define libspectrum_new0( type, count ) \ + ( ( type * ) libspectrum_calloc( sizeof( type ), (count) ) ) + +#define libspectrum_renew( type, mem, count ) \ + ( ( type * ) libspectrum_realloc( (void *)mem, sizeof( type ) * (count) ) ) + /* Attempt to identify a given file */ /* Various types of file we might manage to identify */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-02 13:11:56
|
Revision: 5121 http://sourceforge.net/p/fuse-emulator/code/5121 Author: zubzero Date: 2015-03-02 13:11:54 +0000 (Mon, 02 Mar 2015) Log Message: ----------- Use libspectrum_{new,renew}() macros where sizeof(elem) > 1 Modified Paths: -------------- trunk/libspectrum/accessor.pl trunk/libspectrum/creator.c trunk/libspectrum/csw.c trunk/libspectrum/dck.c trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/ide.c trunk/libspectrum/microdrive.c trunk/libspectrum/pzx_read.c trunk/libspectrum/rzx.c trunk/libspectrum/szx.c trunk/libspectrum/tape.c trunk/libspectrum/tape_block.c trunk/libspectrum/tzx_read.c trunk/libspectrum/tzx_write.c Modified: trunk/libspectrum/accessor.pl =================================================================== --- trunk/libspectrum/accessor.pl 2015-03-02 12:28:08 UTC (rev 5120) +++ trunk/libspectrum/accessor.pl 2015-03-02 13:11:54 UTC (rev 5121) @@ -246,7 +246,7 @@ libspectrum_snap* libspectrum_snap_alloc_internal( void ) { - return libspectrum_malloc( sizeof( libspectrum_snap ) ); + return libspectrum_new( libspectrum_snap, 1 ); } CODE Modified: trunk/libspectrum/creator.c =================================================================== --- trunk/libspectrum/creator.c 2015-03-02 12:28:08 UTC (rev 5120) +++ trunk/libspectrum/creator.c 2015-03-02 13:11:54 UTC (rev 5121) @@ -45,7 +45,7 @@ libspectrum_creator* libspectrum_creator_alloc( void ) { - libspectrum_creator *creator = libspectrum_malloc( sizeof( *creator ) ); + libspectrum_creator *creator = libspectrum_new( libspectrum_creator, 1 ); creator->custom = NULL; creator->custom_length = 0; return creator; Modified: trunk/libspectrum/csw.c =================================================================== --- trunk/libspectrum/csw.c 2015-03-02 12:28:08 UTC (rev 5120) +++ trunk/libspectrum/csw.c 2015-03-02 13:11:54 UTC (rev 5121) @@ -53,7 +53,7 @@ } /* Claim memory for the block */ - block = libspectrum_malloc( sizeof( *block ) ); + block = libspectrum_new( libspectrum_tape_block, 1 ); /* Set the block type */ block->type = LIBSPECTRUM_TAPE_BLOCK_RLE_PULSE; Modified: trunk/libspectrum/dck.c =================================================================== --- trunk/libspectrum/dck.c 2015-03-02 12:28:08 UTC (rev 5120) +++ trunk/libspectrum/dck.c 2015-03-02 13:11:54 UTC (rev 5121) @@ -40,7 +40,7 @@ { size_t i; - *dck = libspectrum_malloc( sizeof( **dck ) ); + *dck = libspectrum_new( libspectrum_dck_block, 1 ); (*dck)->bank = LIBSPECTRUM_DCK_BANK_DOCK; for( i = 0; i < 8; i++ ) { @@ -69,7 +69,7 @@ libspectrum_dck* libspectrum_dck_alloc( void ) { - libspectrum_dck *dck = libspectrum_malloc( sizeof( *dck ) ); + libspectrum_dck *dck = libspectrum_new( libspectrum_dck, 1 ); size_t i; for( i=0; i<256; i++ ) dck->dck[i] = NULL; return dck; Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-02 12:28:08 UTC (rev 5120) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-02 13:11:54 UTC (rev 5121) @@ -975,3 +975,6 @@ 20150302 internals.h,pzx_read.c,szx.c,test/test.c,zxs.c: add and use ARRAY_SIZE macro (Stuart). 20150302 libspectrum.h.in: add libspectrum_{new,new0,renew}() macros (Stuart). +20150302 accessor.pl,creator.c,csw.c,dck.c,ide.c,microdrive.c,pzx_read.c,rzx.c, + szx.c,tape.c,tape_block.c,tzx_read.c,tzx_write.c: use libspectrum_new() + and libspectrum_renew() macros where sizeof(elem) > 1 (Stuart). Modified: trunk/libspectrum/ide.c =================================================================== --- trunk/libspectrum/ide.c 2015-03-02 12:28:08 UTC (rev 5120) +++ trunk/libspectrum/ide.c 2015-03-02 13:11:54 UTC (rev 5121) @@ -195,7 +195,7 @@ { libspectrum_ide_channel *channel; - channel = libspectrum_malloc( sizeof( *channel ) ); + channel = libspectrum_new( libspectrum_ide_channel, 1 ); channel->databus = databus; channel->drive[ LIBSPECTRUM_IDE_MASTER ].disk = NULL; @@ -503,7 +503,7 @@ gint *key; - key = libspectrum_malloc( sizeof( *key ) ); + key = libspectrum_new( gint, 1 ); buffer = libspectrum_malloc( drv->sector_size * sizeof( *buffer ) ); *key = chn->sector_number; Modified: trunk/libspectrum/microdrive.c =================================================================== --- trunk/libspectrum/microdrive.c 2015-03-02 12:28:08 UTC (rev 5120) +++ trunk/libspectrum/microdrive.c 2015-03-02 13:11:54 UTC (rev 5121) @@ -66,7 +66,7 @@ libspectrum_microdrive* libspectrum_microdrive_alloc( void ) { - return libspectrum_malloc( sizeof( libspectrum_microdrive ) ); + return libspectrum_new( libspectrum_microdrive, 1 ); } /* Free a microdrive image */ Modified: trunk/libspectrum/pzx_read.c =================================================================== --- trunk/libspectrum/pzx_read.c 2015-03-02 12:28:08 UTC (rev 5120) +++ trunk/libspectrum/pzx_read.c 2015-03-02 13:11:54 UTC (rev 5121) @@ -154,8 +154,8 @@ } if( *buffer < block_end ) { - ids = libspectrum_malloc( sizeof( *ids ) ); - strings = libspectrum_malloc( sizeof( *strings ) ); + ids = libspectrum_new( int, 1 ); + strings = libspectrum_new( char *, 1 ); count = 1; i = 0; @@ -191,8 +191,8 @@ } i = count++; - ids = libspectrum_realloc( ids, count * sizeof( *ids ) ); - strings = libspectrum_realloc( strings, count * sizeof( *strings ) ); + ids = libspectrum_renew( int, ids, count ); + strings = libspectrum_renew( char *, strings, count ); if( id == -1 ) { size_t new_len = strlen( info_tag ) + strlen( string ) + @@ -347,9 +347,9 @@ libspectrum_error error; size_t buffer_sizes = 64; size_t *pulse_repeats_buffer = - libspectrum_malloc( buffer_sizes * sizeof( size_t ) ); + libspectrum_new( size_t, buffer_sizes ); libspectrum_dword *lengths_buffer = - libspectrum_malloc( buffer_sizes * sizeof( libspectrum_dword ) ); + libspectrum_new( libspectrum_dword, buffer_sizes ); const libspectrum_byte *block_end = *buffer + data_length; while( ( block_end - (*buffer) ) > (ptrdiff_t)0 ) { @@ -365,11 +365,9 @@ if( buffer_sizes == count ) { buffer_sizes *= 2; pulse_repeats_buffer = - libspectrum_realloc( pulse_repeats_buffer, - buffer_sizes * sizeof( size_t ) ); + libspectrum_renew( size_t, pulse_repeats_buffer, buffer_sizes ); lengths_buffer = - libspectrum_realloc( lengths_buffer, - buffer_sizes * sizeof( libspectrum_dword ) ); + libspectrum_renew( libspectrum_dword, lengths_buffer, buffer_sizes ); } } @@ -381,11 +379,9 @@ if( buffer_sizes != count ) { pulse_repeats_buffer = - libspectrum_realloc( pulse_repeats_buffer, - count * sizeof( size_t ) ); + libspectrum_renew( size_t, pulse_repeats_buffer, count ); lengths_buffer = - libspectrum_realloc( lengths_buffer, - count * sizeof( libspectrum_dword ) ); + libspectrum_renew( libspectrum_dword, lengths_buffer, count ); } block = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE ); @@ -597,7 +593,7 @@ return LIBSPECTRUM_ERROR_SIGNATURE; } - ctx = libspectrum_malloc( sizeof( *ctx ) ); + ctx = libspectrum_new( pzx_context, 1 ); ctx->version = 0; while( buffer < end ) { Modified: trunk/libspectrum/rzx.c =================================================================== --- trunk/libspectrum/rzx.c 2015-03-02 12:28:08 UTC (rev 5120) +++ trunk/libspectrum/rzx.c 2015-03-02 13:11:54 UTC (rev 5121) @@ -185,7 +185,7 @@ static void block_alloc( rzx_block_t **block, libspectrum_rzx_block_id type ) { - *block = libspectrum_malloc( sizeof( **block ) ); + *block = libspectrum_new( rzx_block_t, 1 ); (*block)->type = type; } @@ -260,7 +260,7 @@ libspectrum_rzx* libspectrum_rzx_alloc( void ) { - libspectrum_rzx *rzx = libspectrum_malloc( sizeof( *rzx ) ); + libspectrum_rzx *rzx = libspectrum_new( libspectrum_rzx, 1 ); rzx->blocks = NULL; rzx->current_block = NULL; rzx->current_input = NULL; @@ -407,7 +407,8 @@ new_allocated = input->allocated >= 25 ? 2 * input->allocated : 50; if( new_allocated < new_count ) new_allocated = new_count; - ptr = libspectrum_realloc( input->frames, new_allocated * sizeof( *ptr ) ); + ptr = libspectrum_renew( libspectrum_rzx_frame_t, input->frames, + new_allocated ); if( !ptr ) return LIBSPECTRUM_ERROR_MEMORY; input->frames = ptr; @@ -1009,7 +1010,7 @@ (*ptr)++; /* Allocate memory for the frames */ - block->frames = libspectrum_malloc( block->count * sizeof( *block->frames ) ); + block->frames = libspectrum_new( libspectrum_rzx_frame_t, block->count ); block->allocated = block->count; /* Fetch the T-state counter and the flags */ Modified: trunk/libspectrum/szx.c =================================================================== --- trunk/libspectrum/szx.c 2015-03-02 12:28:08 UTC (rev 5120) +++ trunk/libspectrum/szx.c 2015-03-02 13:11:54 UTC (rev 5121) @@ -2399,7 +2399,7 @@ break; } - ctx = libspectrum_malloc( sizeof( *ctx ) ); + ctx = libspectrum_new( szx_context, 1 ); ctx->swap_af = 0; while( buffer < end ) { Modified: trunk/libspectrum/tape.c =================================================================== --- trunk/libspectrum/tape.c 2015-03-02 12:28:08 UTC (rev 5120) +++ trunk/libspectrum/tape.c 2015-03-02 13:11:54 UTC (rev 5121) @@ -130,7 +130,7 @@ libspectrum_tape* libspectrum_tape_alloc( void ) { - libspectrum_tape *tape = libspectrum_malloc( sizeof( *tape ) ); + libspectrum_tape *tape = libspectrum_new( libspectrum_tape, 1 ); tape->blocks = NULL; tape->last_block = NULL; libspectrum_tape_iterator_init( &(tape->state.current_block), tape ); Modified: trunk/libspectrum/tape_block.c =================================================================== --- trunk/libspectrum/tape_block.c 2015-03-02 12:28:08 UTC (rev 5120) +++ trunk/libspectrum/tape_block.c 2015-03-02 13:11:54 UTC (rev 5121) @@ -63,7 +63,7 @@ libspectrum_tape_block* libspectrum_tape_block_alloc( libspectrum_tape_type type ) { - libspectrum_tape_block *block = libspectrum_malloc( sizeof( *block ) ); + libspectrum_tape_block *block = libspectrum_new( libspectrum_tape_block, 1 ); libspectrum_tape_block_set_type( block, type ); return block; } @@ -470,13 +470,15 @@ } - table->symbols = libspectrum_malloc( table->symbols_in_table * sizeof( *table->symbols ) ); + table->symbols = + libspectrum_new( libspectrum_tape_generalised_data_symbol, + table->symbols_in_table ); for( i = 0, symbol = table->symbols; i < table->symbols_in_table; i++, symbol++ ) { symbol->edge_type = **ptr; (*ptr)++; - symbol->lengths = libspectrum_malloc( table->max_pulses * sizeof( *symbol->lengths ) ); + symbol->lengths = libspectrum_new( libspectrum_word, table->max_pulses ); for( j = 0; j < table->max_pulses; j++ ) { symbol->lengths[ j ] = (*ptr)[0] + (*ptr)[1] * 0x100; (*ptr) += 2; Modified: trunk/libspectrum/tzx_read.c =================================================================== --- trunk/libspectrum/tzx_read.c 2015-03-02 12:28:08 UTC (rev 5120) +++ trunk/libspectrum/tzx_read.c 2015-03-02 13:11:54 UTC (rev 5121) @@ -406,7 +406,7 @@ return LIBSPECTRUM_ERROR_CORRUPT; } - lengths = libspectrum_malloc( count * sizeof( *lengths ) ); + lengths = libspectrum_new( libspectrum_dword, count ); /* Copy the data across */ for( i = 0; i < count; i++ ) { @@ -572,7 +572,7 @@ } symbols = libspectrum_malloc( symbol_count * sizeof( *symbols ) ); - repeats = libspectrum_malloc( symbol_count * sizeof( *repeats ) ); + repeats = libspectrum_new( libspectrum_word, symbol_count ); for( i = 0; i < symbol_count; i++ ) { symbols[ i ] = **ptr; (*ptr)++; @@ -772,10 +772,10 @@ libspectrum_tape_block_set_count( block, count ); /* Allocate memory */ - offsets = libspectrum_malloc( count * sizeof( *offsets ) ); + offsets = libspectrum_new( int, count ); libspectrum_tape_block_set_offsets( block, offsets ); - descriptions = libspectrum_malloc( count * sizeof( *descriptions ) ); + descriptions = libspectrum_new( char *, count ); libspectrum_tape_block_set_texts( block, descriptions ); /* Read in the data */ @@ -945,10 +945,10 @@ libspectrum_tape_block_set_count( block, count ); /* Allocate memory */ - ids = libspectrum_malloc( count * sizeof( *ids ) ); + ids = libspectrum_new( int, count ); libspectrum_tape_block_set_ids( block, ids ); - strings = libspectrum_malloc( count * sizeof( *strings ) ); + strings = libspectrum_new( char *, count ); libspectrum_tape_block_set_texts( block, strings ); for( i = 0; i < count; i++ ) { @@ -1014,13 +1014,13 @@ } /* Allocate memory */ - types = libspectrum_malloc( count * sizeof( *types ) ); + types = libspectrum_new( int, count ); libspectrum_tape_block_set_types( block, types ); - ids = libspectrum_malloc( count * sizeof( *ids ) ); + ids = libspectrum_new( int, count ); libspectrum_tape_block_set_ids( block, ids ); - values = libspectrum_malloc( count * sizeof( *values ) ); + values = libspectrum_new( int, count ); libspectrum_tape_block_set_values( block, values ); /* Actually read in all the data */ Modified: trunk/libspectrum/tzx_write.c =================================================================== --- trunk/libspectrum/tzx_write.c 2015-03-02 12:28:08 UTC (rev 5120) +++ trunk/libspectrum/tzx_write.c 2015-03-02 13:11:54 UTC (rev 5121) @@ -947,7 +947,7 @@ if( uncommitted_pulse_count == max_pulse_count ) { max_pulse_count = uncommitted_pulse_count + 64; lengths = - libspectrum_realloc( lengths, max_pulse_count * sizeof( *lengths ) ); + libspectrum_renew( libspectrum_dword, lengths, max_pulse_count ); } /* Queue up pulse */ lengths[uncommitted_pulse_count++] = This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-02 19:15:45
|
Revision: 5122 http://sourceforge.net/p/fuse-emulator/code/5122 Author: zubzero Date: 2015-03-02 19:15:42 +0000 (Mon, 02 Mar 2015) Log Message: ----------- Fix ordering of args in libspectrum_new0() Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/libspectrum.h.in Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-02 13:11:54 UTC (rev 5121) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-02 19:15:42 UTC (rev 5122) @@ -978,3 +978,4 @@ 20150302 accessor.pl,creator.c,csw.c,dck.c,ide.c,microdrive.c,pzx_read.c,rzx.c, szx.c,tape.c,tape_block.c,tzx_read.c,tzx_write.c: use libspectrum_new() and libspectrum_renew() macros where sizeof(elem) > 1 (Stuart). +20150302 libspectrum.in.h: fix ordering of args in libspectrum_new0() (Stuart). Modified: trunk/libspectrum/libspectrum.h.in =================================================================== --- trunk/libspectrum/libspectrum.h.in 2015-03-02 13:11:54 UTC (rev 5121) +++ trunk/libspectrum/libspectrum.h.in 2015-03-02 19:15:42 UTC (rev 5122) @@ -153,7 +153,7 @@ ( ( type * ) libspectrum_malloc( sizeof( type ) * (count) ) ) #define libspectrum_new0( type, count ) \ - ( ( type * ) libspectrum_calloc( sizeof( type ), (count) ) ) + ( ( type * ) libspectrum_calloc( (count), sizeof( type ) ) ) #define libspectrum_renew( type, mem, count ) \ ( ( type * ) libspectrum_realloc( (void *)mem, sizeof( type ) * (count) ) ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-02 19:18:36
|
Revision: 5123 http://sourceforge.net/p/fuse-emulator/code/5123 Author: zubzero Date: 2015-03-02 19:18:29 +0000 (Mon, 02 Mar 2015) Log Message: ----------- Z80 snapshots: fix overallocation for uncompressed v2 data blocks Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/z80.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-02 19:15:42 UTC (rev 5122) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-02 19:18:29 UTC (rev 5123) @@ -979,3 +979,4 @@ szx.c,tape.c,tape_block.c,tzx_read.c,tzx_write.c: use libspectrum_new() and libspectrum_renew() macros where sizeof(elem) > 1 (Stuart). 20150302 libspectrum.in.h: fix ordering of args in libspectrum_new0() (Stuart). +20150302 z80.c: fix overallocation for uncompressed v2 data blocks (Stuart). Modified: trunk/libspectrum/z80.c =================================================================== --- trunk/libspectrum/z80.c 2015-03-02 19:15:42 UTC (rev 5122) +++ trunk/libspectrum/z80.c 2015-03-02 19:18:29 UTC (rev 5123) @@ -1105,7 +1105,7 @@ return LIBSPECTRUM_ERROR_CORRUPT; } - *block = libspectrum_malloc( 0x4000 * sizeof( *block ) ); + *block = libspectrum_malloc( 0x4000 * sizeof( **block ) ); memcpy( *block, buffer + 3, 0x4000 ); *length = 0x4000; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-02 19:51:45
|
Revision: 5124 http://sourceforge.net/p/fuse-emulator/code/5124 Author: zubzero Date: 2015-03-02 19:51:36 +0000 (Mon, 02 Mar 2015) Log Message: ----------- Use libspectrum_{new,new0,renew}() macros where sizeof(elem) == 1 Modified Paths: -------------- trunk/libspectrum/bzip2.c trunk/libspectrum/crypto.c trunk/libspectrum/csw.c trunk/libspectrum/dck.c trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/ide.c trunk/libspectrum/libspectrum.c trunk/libspectrum/microdrive.c trunk/libspectrum/plusd.c trunk/libspectrum/pzx_read.c trunk/libspectrum/rzx.c trunk/libspectrum/sna.c trunk/libspectrum/snapshot.c trunk/libspectrum/sp.c trunk/libspectrum/szx.c trunk/libspectrum/tap.c trunk/libspectrum/test/test.c trunk/libspectrum/tzx_read.c trunk/libspectrum/tzx_write.c trunk/libspectrum/warajevo_read.c trunk/libspectrum/wav.c trunk/libspectrum/z80.c trunk/libspectrum/z80em.c trunk/libspectrum/zlib.c trunk/libspectrum/zxs.c Modified: trunk/libspectrum/bzip2.c =================================================================== --- trunk/libspectrum/bzip2.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/bzip2.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -44,7 +44,7 @@ /* Known length, so we can use the easy method */ if( *outlength ) { - *outptr = libspectrum_malloc( *outlength ); + *outptr = libspectrum_new( libspectrum_byte, *outlength ); length2 = *outlength; error = BZ2_bzBuffToBuffDecompress( (char*)*outptr, &length2, (char*)bzptr, @@ -66,7 +66,7 @@ length = bzlength; - *outptr = libspectrum_malloc( length ); + *outptr = libspectrum_new( libspectrum_byte, length ); /* Use standard memory allocation/free routines */ stream.bzalloc = NULL; stream.bzfree = NULL; stream.opaque = NULL; @@ -113,13 +113,13 @@ return LIBSPECTRUM_ERROR_LOGIC; } *outlength = stream.total_out_lo32; - *outptr = libspectrum_realloc( *outptr, *outlength ); + *outptr = libspectrum_renew( libspectrum_byte, *outptr, *outlength ); return LIBSPECTRUM_ERROR_NONE; case BZ_OK: /* More output space required */ length += bzlength; - ptr = libspectrum_realloc( *outptr, length ); + ptr = libspectrum_renew( libspectrum_byte, *outptr, length ); *outptr = ptr; stream.next_out = (char*)*outptr + stream.total_out_lo32; stream.avail_out += bzlength; Modified: trunk/libspectrum/crypto.c =================================================================== --- trunk/libspectrum/crypto.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/crypto.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -120,7 +120,7 @@ gcry_mpi_t hash_mpi; digest_length = gcry_md_get_algo_dlen( HASH_ALGORITHM ); - digest = libspectrum_malloc( digest_length ); + digest = libspectrum_new( unsigned char, digest_length ); gcry_md_hash_buffer( HASH_ALGORITHM, digest, data, data_length ); @@ -270,7 +270,7 @@ length += length_s; *signature_length = length; - *signature = libspectrum_malloc( length ); + *signature = libspectrum_new( libspectrum_byte, length ); error = gcry_mpi_print( GCRYMPI_FMT_PGP, *signature, length, &length, r ); if( error ) { Modified: trunk/libspectrum/csw.c =================================================================== --- trunk/libspectrum/csw.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/csw.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -126,7 +126,7 @@ } else { /* Claim memory for the data (it's one big lump) */ csw_block->length = length; - csw_block->data = libspectrum_malloc( length ); + csw_block->data = libspectrum_new( libspectrum_byte, length ); /* Copy the data across */ memcpy( csw_block->data, buffer, length ); Modified: trunk/libspectrum/dck.c =================================================================== --- trunk/libspectrum/dck.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/dck.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -205,7 +205,7 @@ break; case LIBSPECTRUM_DCK_PAGE_RAM_EMPTY: dck->dck[num_dck_block]->pages[i] = - libspectrum_calloc( DCK_PAGE_SIZE, sizeof( libspectrum_byte ) ); + libspectrum_new0( libspectrum_byte, DCK_PAGE_SIZE ); if( !dck->dck[num_dck_block]->pages[i] ) { libspectrum_print_error( LIBSPECTRUM_ERROR_MEMORY, "libspectrum_dck_read: out of memory" ); @@ -216,7 +216,7 @@ case LIBSPECTRUM_DCK_PAGE_ROM: case LIBSPECTRUM_DCK_PAGE_RAM: dck->dck[num_dck_block]->pages[i] = - libspectrum_malloc( DCK_PAGE_SIZE * sizeof( libspectrum_byte ) ); + libspectrum_new( libspectrum_byte, DCK_PAGE_SIZE ); memcpy( dck->dck[num_dck_block]->pages[i], buffer, DCK_PAGE_SIZE ); buffer += DCK_PAGE_SIZE; break; Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-02 19:51:36 UTC (rev 5124) @@ -980,3 +980,8 @@ and libspectrum_renew() macros where sizeof(elem) > 1 (Stuart). 20150302 libspectrum.in.h: fix ordering of args in libspectrum_new0() (Stuart). 20150302 z80.c: fix overallocation for uncompressed v2 data blocks (Stuart). +20150302 bzip2.c,crypto.c,csw.c,dck.c,ide.c,libspectrum.c,microdrive.c,plusd.c, + pzx_read.c,rzx.c,sna.c,snapshot.c,sp.c,szx.c,tap.c,test/test.c, + tzx_read.c,tzx_write.c,warajevo_read.c,wav.c,z80.c,z80em.c,zlib.c, + zxs.c: use libspectrum_{new,new0,renew}() macros where + sizeof(elem) == 1 (Stuart). Modified: trunk/libspectrum/ide.c =================================================================== --- trunk/libspectrum/ide.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/ide.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -504,7 +504,7 @@ gint *key; key = libspectrum_new( gint, 1 ); - buffer = libspectrum_malloc( drv->sector_size * sizeof( *buffer ) ); + buffer = libspectrum_new( libspectrum_byte, drv->sector_size ); *key = chn->sector_number; g_hash_table_insert( cache, key, buffer ); Modified: trunk/libspectrum/libspectrum.c =================================================================== --- trunk/libspectrum/libspectrum.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/libspectrum.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -871,7 +871,7 @@ #else /* #ifndef __MORPHOS__ */ if( xfdDecrunchBuffer( xfdobj ) ) { #endif /* #ifndef __MORPHOS__ */ - *new_buffer = libspectrum_malloc( xfdobj->xfdbi_TargetBufSaveLen ); + *new_buffer = libspectrum_new( char, xfdobj->xfdbi_TargetBufSaveLen ); *new_length = xfdobj->xfdbi_TargetBufSaveLen; memcpy( *new_buffer, xfdobj->xfdbi_TargetBuffer, *new_length ); #ifndef __MORPHOS__ @@ -921,7 +921,7 @@ } /* Ensure there is room for `requested' characters after the current - position `ptr' in `buffer'. If not, realloc() and update the + position `ptr' in `buffer'. If not, renew() and update the pointers as necessary */ void libspectrum_make_room( libspectrum_byte **dest, size_t requested, @@ -932,7 +932,7 @@ if( *allocated == 0 ) { (*allocated) = requested; - *dest = libspectrum_malloc( requested * sizeof( **dest ) ); + *dest = libspectrum_new( libspectrum_byte, requested ); } else { current_length = *ptr - *dest; @@ -947,7 +947,7 @@ current_length + requested : 2 * (*allocated); - *dest = libspectrum_realloc( *dest, *allocated * sizeof( **dest ) ); + *dest = libspectrum_renew( libspectrum_byte, *dest, *allocated ); } /* Update the secondary pointer to the block */ Modified: trunk/libspectrum/microdrive.c =================================================================== --- trunk/libspectrum/microdrive.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/microdrive.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -289,7 +289,7 @@ libspectrum_byte **buffer, size_t *length ) { *length = microdrive->cartridge_len * LIBSPECTRUM_MICRODRIVE_BLOCK_LEN; - *buffer = libspectrum_malloc( ( *length + 1 ) * sizeof( **buffer ) ); + *buffer = libspectrum_new( libspectrum_byte, *length + 1 ); memcpy( *buffer, microdrive->data, *length ); Modified: trunk/libspectrum/plusd.c =================================================================== --- trunk/libspectrum/plusd.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/plusd.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -209,7 +209,7 @@ libspectrum_byte *ram; - ram = libspectrum_malloc( 0x4000 * sizeof( *ram ) ); + ram = libspectrum_new( libspectrum_byte, 0x4000 ); libspectrum_snap_set_pages( snap, i, ram ); memcpy( ram, buffer, 0x4000 ); Modified: trunk/libspectrum/pzx_read.c =================================================================== --- trunk/libspectrum/pzx_read.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/pzx_read.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -197,7 +197,7 @@ if( id == -1 ) { size_t new_len = strlen( info_tag ) + strlen( string ) + strlen( ": " ) + 1; - char *comment = libspectrum_malloc( new_len ); + char *comment = libspectrum_new( char, new_len ); snprintf( comment, new_len, "%s: %s", info_tag, string ); libspectrum_free( string ); ids[i] = 0xff; @@ -620,9 +620,9 @@ } /* Allocate memory for the data; the check for *length is to avoid - the implementation-defined of malloc( 0 ) */ + the implementation-defined behaviour of malloc( 0 ) */ if( length ) { - *data = libspectrum_malloc( ( length ) * sizeof( **data ) ); + *data = libspectrum_new( libspectrum_byte, length ); /* Copy the block data across, and move along */ memcpy( *data, *ptr, length ); *ptr += length; } else { @@ -639,13 +639,12 @@ size_t length = 0; char *ptr2; size_t buffer_size = 64; - char *buffer = - libspectrum_malloc( buffer_size * sizeof( char ) ); + char *buffer = libspectrum_new( char, buffer_size ); while( **ptr != '\0' && *ptr < end ) { if( length == buffer_size ) { buffer_size *= 2; - buffer = libspectrum_realloc( buffer, buffer_size * sizeof( char ) ); + buffer = libspectrum_renew( char, buffer, buffer_size ); } *(buffer + length++) = **ptr; (*ptr)++; } @@ -653,7 +652,7 @@ /* Advance past the null terminator if it isn't the end of the block */ if( **ptr == '\0' && *ptr < end ) (*ptr)++; - *dest = libspectrum_malloc( (length + 1) * sizeof( libspectrum_byte ) ); + *dest = libspectrum_new( char, (length + 1) ); strncpy( *dest, buffer, length ); Modified: trunk/libspectrum/rzx.c =================================================================== --- trunk/libspectrum/rzx.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/rzx.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -73,7 +73,7 @@ /* Used for recording to note the last non-repeated frame. We can't really use a direct pointer to the frame here as that will move - around when we do a realloc on the array, so just dereference it + around when we do a renew on the array, so just dereference it every time */ size_t non_repeat; @@ -468,7 +468,7 @@ if( count ) { - frame->in_bytes = libspectrum_malloc( count * sizeof( *( frame->in_bytes ) ) ); + frame->in_bytes = libspectrum_new( libspectrum_byte, count ); memcpy( frame->in_bytes, in_bytes, count * sizeof( *( frame->in_bytes ) ) ); @@ -1113,7 +1113,7 @@ if( block->frames[i].count ) { block->frames[i].in_bytes = - libspectrum_malloc( block->frames[i].count * sizeof( libspectrum_byte ) ); + libspectrum_new( libspectrum_byte, block->frames[i].count ); memcpy( block->frames[i].in_bytes, *ptr, block->frames[i].count ); } else { Modified: trunk/libspectrum/sna.c =================================================================== --- trunk/libspectrum/sna.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/sna.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -185,7 +185,7 @@ case LIBSPECTRUM_MACHINE_PENT: for( i=0; i<8; i++ ) { - libspectrum_byte *ram = libspectrum_malloc( 0x4000 * sizeof( *ram ) ); + libspectrum_byte *ram = libspectrum_new( libspectrum_byte, 0x4000 ); libspectrum_snap_set_pages( snap, i, ram ); } Modified: trunk/libspectrum/snapshot.c =================================================================== --- trunk/libspectrum/snapshot.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/snapshot.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -424,7 +424,7 @@ } for( i = 0; i < 3; i++ ) - buffer[i] = libspectrum_malloc( 0x4000 * sizeof( libspectrum_byte ) ); + buffer[i] = libspectrum_new( libspectrum_byte, 0x4000 ); libspectrum_snap_set_pages( snap, 5, buffer[0] ); libspectrum_snap_set_pages( snap, 2, buffer[1] ); Modified: trunk/libspectrum/sp.c =================================================================== --- trunk/libspectrum/sp.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/sp.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -116,7 +116,7 @@ /* Get me 48K of zero-ed memory and then copy in the bits that were represented in the snap */ - memory = libspectrum_calloc( 0xc000, sizeof( libspectrum_byte ) ); + memory = libspectrum_new0( libspectrum_byte, 0xc000 ); memcpy( &memory[ start ], buffer, memory_length ); Modified: trunk/libspectrum/szx.c =================================================================== --- trunk/libspectrum/szx.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/szx.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -396,7 +396,7 @@ return LIBSPECTRUM_ERROR_UNKNOWN; } - *data = libspectrum_malloc( uncompressed_length * sizeof( **data ) ); + *data = libspectrum_new( libspectrum_byte, uncompressed_length ); memcpy( *data, *buffer, uncompressed_length ); *buffer += uncompressed_length; @@ -543,7 +543,7 @@ return LIBSPECTRUM_ERROR_UNKNOWN; } - rom_data = libspectrum_malloc( expected_length ); + rom_data = libspectrum_new( libspectrum_byte, expected_length ); memcpy( rom_data, *buffer, expected_length ); } @@ -576,7 +576,7 @@ /* This is ugly, but I can't see a better way to do it */ if( sizeof( libspectrum_byte ) == sizeof( char ) ) { - char *custom = libspectrum_malloc( data_length + 1 ); + char *custom = libspectrum_new( char, data_length + 1 ); memcpy( custom, *buffer, data_length ); custom[data_length] = 0; @@ -775,13 +775,13 @@ expected_length = 0x800; - ram_data = libspectrum_malloc( expected_length ); + ram_data = libspectrum_new( libspectrum_byte, expected_length ); memcpy( ram_data, *buffer, expected_length ); *buffer += expected_length; if( libspectrum_snap_opus_custom_rom( snap ) ) { expected_length = 0x2000; - rom_data = libspectrum_malloc( expected_length ); + rom_data = libspectrum_new( libspectrum_byte, expected_length ); memcpy( rom_data, *buffer, expected_length ); *buffer += expected_length; } @@ -958,12 +958,12 @@ return LIBSPECTRUM_ERROR_UNKNOWN; } - ram_data = libspectrum_malloc( expected_length ); + ram_data = libspectrum_new( libspectrum_byte, expected_length ); memcpy( ram_data, *buffer, expected_length ); *buffer += expected_length; if( libspectrum_snap_plusd_custom_rom( snap ) ) { - rom_data = libspectrum_malloc( expected_length ); + rom_data = libspectrum_new( libspectrum_byte, expected_length ); memcpy( rom_data, *buffer, expected_length ); *buffer += expected_length; } @@ -1556,7 +1556,7 @@ return LIBSPECTRUM_ERROR_UNKNOWN; } - rom_data = libspectrum_malloc( expected_length ); + rom_data = libspectrum_new( libspectrum_byte, expected_length ); memcpy( rom_data, *buffer, expected_length ); libspectrum_snap_set_interface1_rom_length( snap, 0, expected_length ); @@ -1574,7 +1574,7 @@ libspectrum_byte *rom_data, libspectrum_word length ) { if( length ) { - libspectrum_byte *page = libspectrum_malloc( length ); + libspectrum_byte *page = libspectrum_new( libspectrum_byte, length ); memcpy( page, rom_data, length ); libspectrum_snap_set_roms( snap, page_no, page ); @@ -1683,7 +1683,7 @@ return LIBSPECTRUM_ERROR_UNKNOWN; } - rom_data = libspectrum_malloc( expected_length ); + rom_data = libspectrum_new( libspectrum_byte, expected_length ); memcpy( rom_data, *buffer, expected_length ); *buffer += expected_length; } @@ -1922,7 +1922,7 @@ return LIBSPECTRUM_ERROR_UNKNOWN; } - eprom_data = libspectrum_malloc( expected_length ); + eprom_data = libspectrum_new( libspectrum_byte, expected_length ); memcpy( eprom_data, *buffer, expected_length ); *buffer += expected_length; @@ -2029,7 +2029,7 @@ *buffer += data_length; } - data_out = libspectrum_malloc( 0x20000 ); + data_out = libspectrum_new( libspectrum_byte, 0x20000 ); memcpy( data_out, data, 0x20000 ); setter( snap, 0, data_out ); @@ -2073,7 +2073,7 @@ libspectrum_snap_set_spectranet_programmable_trap( snap, libspectrum_read_word( buffer ) ); - w5100 = libspectrum_malloc( 0x30 * sizeof( libspectrum_byte ) ); + w5100 = libspectrum_new( libspectrum_byte, 0x30 ); libspectrum_snap_set_spectranet_w5100( snap, 0, w5100 ); memcpy( w5100, *buffer, 0x30 ); (*buffer) += 0x30; @@ -2959,7 +2959,7 @@ uncompressed_data_length = data_length; - data = libspectrum_malloc( data_length ); + data = libspectrum_new( libspectrum_byte, data_length ); rom_base = data; /* Copy the rom data into a single block ready for putting in the szx */ Modified: trunk/libspectrum/tap.c =================================================================== --- trunk/libspectrum/tap.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/tap.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -102,7 +102,7 @@ } /* Allocate memory for the data */ - data = libspectrum_malloc( data_length * sizeof( *data ) ); + data = libspectrum_new( libspectrum_byte, data_length ); libspectrum_tape_block_set_data( block, data ); /* Copy the block data across */ Modified: trunk/libspectrum/test/test.c =================================================================== --- trunk/libspectrum/test/test.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/test/test.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -39,7 +39,7 @@ } *length = info.st_size; - *buffer = libspectrum_malloc( *length ); + *buffer = libspectrum_new( libspectrum_byte, *length ); bytes = read( fd, *buffer, *length ); if( bytes == -1 ) { Modified: trunk/libspectrum/tzx_read.c =================================================================== --- trunk/libspectrum/tzx_read.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/tzx_read.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -571,7 +571,7 @@ return LIBSPECTRUM_ERROR_CORRUPT; } - symbols = libspectrum_malloc( symbol_count * sizeof( *symbols ) ); + symbols = libspectrum_new( libspectrum_byte, symbol_count ); repeats = libspectrum_new( libspectrum_word, symbol_count ); for( i = 0; i < symbol_count; i++ ) { @@ -602,7 +602,7 @@ data_count = ( ( bits_per_symbol * symbol_count ) + 7 ) / 8; data_size = data_count * sizeof( *data ); - data = libspectrum_malloc( data_size ); + data = libspectrum_new( libspectrum_byte, data_size ); if( end - (*ptr) < data_size ) { libspectrum_free( data ); @@ -1054,7 +1054,7 @@ block = libspectrum_tape_block_alloc( LIBSPECTRUM_TAPE_BLOCK_CUSTOM ); /* Get the description */ - description = libspectrum_malloc( 17 * sizeof( libspectrum_byte ) ); + description = libspectrum_new( char, 17 ); memcpy( description, *ptr, 16 ); (*ptr) += 16; description[16] = '\0'; libspectrum_tape_block_set_text( block, description ); @@ -1124,9 +1124,9 @@ } /* Allocate memory for the data; the check for *length is to avoid - the implementation-defined of malloc( 0 ) */ + the implementation-defined behaviour of malloc( 0 ) */ if( *length || padding ) { - *data = libspectrum_malloc( ( *length + padding ) * sizeof( **data ) ); + *data = libspectrum_new( libspectrum_byte, *length + padding ); /* Copy the block data across, and move along */ memcpy( *data, *ptr, *length ); *ptr += *length; } else { Modified: trunk/libspectrum/tzx_write.c =================================================================== --- trunk/libspectrum/tzx_write.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/tzx_write.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -780,8 +780,9 @@ if( rle_state.tape_length <= target_size ) { rle_state.tape_length = target_size * 2; - rle_state.tape_buffer = libspectrum_realloc( rle_state.tape_buffer, - rle_state.tape_length ); + rle_state.tape_buffer = libspectrum_renew( libspectrum_byte, + rle_state.tape_buffer, + rle_state.tape_length ); } for( i = pulse_length; i > 0; i-- ) { @@ -824,7 +825,7 @@ rle_state.level = 0; rle_state.length = 0; rle_state.tape_length = 8192; - rle_state.tape_buffer = libspectrum_malloc( rle_state.tape_length ); + rle_state.tape_buffer = libspectrum_new( libspectrum_byte, rle_state.tape_length ); *rle_state.tape_buffer = 0; @@ -998,7 +999,7 @@ /* And the actual data */ data_length = libspectrum_tape_block_data_length( block ); libspectrum_tape_block_set_data_length( pure_data, data_length ); - libspectrum_byte *data = libspectrum_malloc( data_length * sizeof( *data ) ); + libspectrum_byte *data = libspectrum_new( libspectrum_byte, data_length ); memcpy( data, libspectrum_tape_block_data( block ), data_length ); libspectrum_tape_block_set_data( pure_data, data ); Modified: trunk/libspectrum/warajevo_read.c =================================================================== --- trunk/libspectrum/warajevo_read.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/warajevo_read.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -473,7 +473,7 @@ } /* Allocate memory for the data */ - block_data = libspectrum_malloc( length * sizeof( *block_data ) ); + block_data = libspectrum_new( libspectrum_byte, length ); libspectrum_tape_block_set_data( block, block_data ); /* Add flag */ @@ -534,7 +534,7 @@ } /* Allocate memory for the data */ - block_data = libspectrum_malloc( length * sizeof( libspectrum_byte ) ); + block_data = libspectrum_new( libspectrum_byte, length ); libspectrum_tape_block_set_data( block, block_data ); if( compressed_size != decompressed_size ) { @@ -594,8 +594,9 @@ /* Combine the two blocks */ size_t new_length = libspectrum_tape_block_data_length( last_block ) + length; - block_data = libspectrum_realloc( libspectrum_tape_block_data( last_block ), - new_length * sizeof( libspectrum_byte ) ); + block_data = libspectrum_renew( libspectrum_byte, + libspectrum_tape_block_data( last_block ), + new_length ); memcpy( block_data + libspectrum_tape_block_data_length( last_block ), libspectrum_tape_block_data( block ), length ); Modified: trunk/libspectrum/wav.c =================================================================== --- trunk/libspectrum/wav.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/wav.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -88,8 +88,8 @@ tape_length = length; if( tape_length%8 ) tape_length += 8 - (tape_length%8); - buffer = libspectrum_calloc( tape_length * afGetChannels(handle, track), - sizeof( *buffer ) ); + buffer = libspectrum_new0( libspectrum_byte, + tape_length * afGetChannels(handle, track) ); frames = afReadFrames( handle, track, buffer, length ); if( frames == -1 ) { @@ -135,7 +135,7 @@ data_length = tape_length / LIBSPECTRUM_BITS_IN_BYTE; libspectrum_tape_block_set_data_length( block, data_length ); - tape_buffer = libspectrum_calloc( data_length, sizeof( *tape_buffer ) ); + tape_buffer = libspectrum_new0( libspectrum_byte, data_length ); libspectrum_byte *from = buffer; libspectrum_byte *to = tape_buffer; Modified: trunk/libspectrum/z80.c =================================================================== --- trunk/libspectrum/z80.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/z80.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -831,7 +831,7 @@ libspectrum_byte *buffer; /* Should expand to 6912 bytes, so give me a buffer that long */ - buffer = libspectrum_malloc( 6912 * sizeof( *buffer ) ); + buffer = libspectrum_new( libspectrum_byte, 6912 ); if( screen_length == 6912 ) { /* Not compressed */ @@ -899,7 +899,7 @@ /* If it is an Interface 1 ROM page put it in the appropriate structure */ if( page == 1 && libspectrum_snap_interface1_active( snap ) ) { - libspectrum_byte *chunk = libspectrum_malloc( 0x4000 * sizeof( *chunk ) ); + libspectrum_byte *chunk = libspectrum_new( libspectrum_byte, 0x4000 ); memcpy( chunk, uncompressed, 0x4000 ); libspectrum_snap_set_interface1_custom_rom( snap, 1 ); libspectrum_snap_set_interface1_rom( snap, 0, chunk ); @@ -911,10 +911,10 @@ /* If it is a +D ROM/RAM page put it in the appropriate structures */ if( page == 1 && libspectrum_snap_plusd_active( snap ) ) { /* Bottom 8K of page is +D ROM, upper 8K is +D RAM */ - libspectrum_byte *chunk = libspectrum_malloc( 0x2000 * sizeof( *chunk ) ); + libspectrum_byte *chunk = libspectrum_new( libspectrum_byte, 0x2000 ); memcpy( chunk, uncompressed, 0x2000 ); libspectrum_snap_set_plusd_rom( snap, 0, chunk ); - chunk = libspectrum_malloc( 0x2000 * sizeof( *chunk ) ); + chunk = libspectrum_new( libspectrum_byte, 0x2000 ); memcpy( chunk, uncompressed + 0x2000, 0x2000 ); libspectrum_snap_set_plusd_ram( snap, 0, chunk ); libspectrum_free( uncompressed ); @@ -1052,7 +1052,7 @@ return LIBSPECTRUM_ERROR_CORRUPT; } - *uncompressed = libspectrum_malloc( 0xc000 * sizeof( **uncompressed ) ); + *uncompressed = libspectrum_new( libspectrum_byte, 0xc000 ); memcpy( *uncompressed, buffer, 0xc000 ); *next_block = buffer + 0xc000; } @@ -1105,7 +1105,7 @@ return LIBSPECTRUM_ERROR_CORRUPT; } - *block = libspectrum_malloc( 0x4000 * sizeof( **block ) ); + *block = libspectrum_new( libspectrum_byte, 0x4000 ); memcpy( *block, buffer + 3, 0x4000 ); *length = 0x4000; @@ -1514,7 +1514,7 @@ /* If Interface 1 is enabled, write the Interface 1 ROM in Z80 page 1 */ if( libspectrum_snap_interface1_active( snap ) && libspectrum_snap_interface1_custom_rom( snap ) ) { - libspectrum_byte *uncompressed = libspectrum_calloc( 0x4000, sizeof( *uncompressed ) ); + libspectrum_byte *uncompressed = libspectrum_new0( libspectrum_byte, 0x4000 ); memcpy( uncompressed, libspectrum_snap_interface1_rom( snap, 0 ), libspectrum_snap_interface1_rom_length( snap, 0 ) ); @@ -1529,7 +1529,7 @@ RAM if we also overwrite the ROM with 0 */ if( libspectrum_snap_plusd_active( snap ) && libspectrum_snap_plusd_custom_rom( snap ) ) { - libspectrum_byte *uncompressed = libspectrum_malloc( 0x4000 * sizeof( *uncompressed ) ); + libspectrum_byte *uncompressed = libspectrum_new( libspectrum_byte, 0x4000 ); memcpy( uncompressed, libspectrum_snap_plusd_rom( snap, 0 ), 0x2000 ); memcpy( uncompressed + 0x2000, @@ -1709,7 +1709,7 @@ /* Allocate memory for dest if requested */ if( *dest_length == 0 ) { *dest_length = src_length/2; - *dest = libspectrum_malloc( *dest_length * sizeof( **dest ) ); + *dest = libspectrum_new( libspectrum_byte, *dest_length ); } in_ptr = src; @@ -1792,7 +1792,7 @@ /* Allocate memory for dest if requested */ if( *dest_length == 0 ) { *dest_length = src_length / 2; - *dest = libspectrum_malloc( *dest_length * sizeof( **dest ) ); + *dest = libspectrum_new( libspectrum_byte, *dest_length ); } in_ptr = src; Modified: trunk/libspectrum/z80em.c =================================================================== --- trunk/libspectrum/z80em.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/z80em.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -63,7 +63,7 @@ /* Claim memory for the data (it's one big lump) */ z80em_block->length = length; - z80em_block->data = libspectrum_malloc( length ); + z80em_block->data = libspectrum_new( libspectrum_byte, length ); /* Copy the data across */ memcpy( z80em_block->data, buffer, length ); Modified: trunk/libspectrum/zlib.c =================================================================== --- trunk/libspectrum/zlib.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/zlib.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -129,7 +129,7 @@ if( *outlength ) { - *outptr = libspectrum_malloc( *outlength ); + *outptr = libspectrum_new( libspectrum_byte, *outlength ); stream.next_out = *outptr; stream.avail_out = *outlength; error = inflate( &stream, Z_FINISH ); @@ -143,7 +143,7 @@ libspectrum_byte *ptr; *outlength += 16384; stream.avail_out += 16384; - ptr = libspectrum_realloc( *outptr, *outlength ); + ptr = libspectrum_renew( libspectrum_byte, *outptr, *outlength ); stream.next_out = ptr + ( stream.next_out - *outptr ); *outptr = ptr; @@ -154,7 +154,7 @@ } *outlength = stream.next_out - *outptr; - *outptr = libspectrum_realloc( *outptr, *outlength ); + *outptr = libspectrum_renew( libspectrum_byte, *outptr, *outlength ); switch( error ) { @@ -318,7 +318,7 @@ uLongf gzl = (uLongf)( length * 1.001 ) + 12; int gzret; - *gzptr = libspectrum_malloc( gzl ); + *gzptr = libspectrum_new( libspectrum_byte, gzl ); gzret = compress2( *gzptr, &gzl, data, length, Z_BEST_COMPRESSION ); switch (gzret) { Modified: trunk/libspectrum/zxs.c =================================================================== --- trunk/libspectrum/zxs.c 2015-03-02 19:18:29 UTC (rev 5123) +++ trunk/libspectrum/zxs.c 2015-03-02 19:51:36 UTC (rev 5124) @@ -70,8 +70,7 @@ *uncompressed_length = libspectrum_read_dword( compressed ); /* Some space to put the zlib header for decompression */ - zlib_buffer = - libspectrum_malloc( ( compressed_length + 6 ) * sizeof( *zlib_buffer ) ); + zlib_buffer = libspectrum_new( libspectrum_byte, ( compressed_length + 6 ) ); /* zlib's header */ zlib_buffer[0] = 0x78; zlib_buffer[1] = 0xda; @@ -79,7 +78,7 @@ memcpy( &zlib_buffer[2], *compressed, compressed_length ); *compressed += compressed_length; - *uncompressed = libspectrum_malloc( *uncompressed_length * sizeof( **uncompressed ) ); + *uncompressed = libspectrum_new( libspectrum_byte, *uncompressed_length ); actual_length = *uncompressed_length; error = uncompress( *uncompressed, &actual_length, zlib_buffer, @@ -378,7 +377,7 @@ return LIBSPECTRUM_ERROR_UNKNOWN; } - buffer2 = libspectrum_malloc( 0x4000 * sizeof( *buffer2 ) ); + buffer2 = libspectrum_new( libspectrum_byte, 0x4000 ); memcpy( buffer2, buffer, 0x4000 ); *buffer += 0x4000; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-02 22:32:13
|
Revision: 5127 http://sourceforge.net/p/fuse-emulator/code/5127 Author: zubzero Date: 2015-03-02 22:32:05 +0000 (Mon, 02 Mar 2015) Log Message: ----------- Check for overflow in libspectrum_calloc() Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/memory.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-02 21:12:30 UTC (rev 5126) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-02 22:32:05 UTC (rev 5127) @@ -985,3 +985,4 @@ tzx_read.c,tzx_write.c,warajevo_read.c,wav.c,z80.c,z80em.c,zlib.c, zxs.c: use libspectrum_{new,new0,renew}() macros where sizeof(elem) == 1 (Stuart). +20150302 memory.c: check for overflow in libspectrum_calloc() (Stuart). Modified: trunk/libspectrum/memory.c =================================================================== --- trunk/libspectrum/memory.c 2015-03-02 21:12:30 UTC (rev 5126) +++ trunk/libspectrum/memory.c 2015-03-02 22:32:05 UTC (rev 5127) @@ -48,8 +48,12 @@ void* libspectrum_calloc( size_t nmemb, size_t size ) { - void *ptr = libspectrum_calloc_fn( nmemb, size ); + void *ptr; + if( nmemb > SIZE_MAX / size ) abort(); + + ptr = libspectrum_calloc_fn( nmemb, size ); + /* If nmemb * size == 0, acceptable to return NULL */ if( ( nmemb * size ) && !ptr ) abort(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-02 22:35:06
|
Revision: 5128 http://sourceforge.net/p/fuse-emulator/code/5128 Author: zubzero Date: 2015-03-02 22:35:04 +0000 (Mon, 02 Mar 2015) Log Message: ----------- Add libspectrum_{m,re}alloc_n() and use for libspectrum_{new,renew}() macros Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/libspectrum.h.in trunk/libspectrum/memory.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-02 22:32:05 UTC (rev 5127) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-02 22:35:04 UTC (rev 5128) @@ -986,3 +986,5 @@ zxs.c: use libspectrum_{new,new0,renew}() macros where sizeof(elem) == 1 (Stuart). 20150302 memory.c: check for overflow in libspectrum_calloc() (Stuart). +20150302 libspectrum.h.in,memory.c: add libspectrum_{m,re}alloc_n() and use this + for libspectrum_{new,renew}() macros (Stuart). Modified: trunk/libspectrum/libspectrum.h.in =================================================================== --- trunk/libspectrum/libspectrum.h.in 2015-03-02 22:32:05 UTC (rev 5127) +++ trunk/libspectrum/libspectrum.h.in 2015-03-02 22:35:04 UTC (rev 5128) @@ -143,20 +143,22 @@ } libspectrum_mem_vtable_t; WIN32_DLL void* libspectrum_malloc( size_t size ); +WIN32_DLL void* libspectrum_malloc_n( size_t nmemb, size_t size ); WIN32_DLL void* libspectrum_calloc( size_t nmemb, size_t size ); WIN32_DLL void* libspectrum_realloc( void *ptr, size_t size ); +WIN32_DLL void* libspectrum_realloc_n( void *ptr, size_t nmemb, size_t size ); WIN32_DLL void libspectrum_free( void *ptr ); WIN32_DLL void libspectrum_mem_set_vtable( libspectrum_mem_vtable_t *table ); #define libspectrum_new( type, count ) \ - ( ( type * ) libspectrum_malloc( sizeof( type ) * (count) ) ) + ( ( type * ) libspectrum_malloc_n( (count), sizeof( type ) ) ) #define libspectrum_new0( type, count ) \ ( ( type * ) libspectrum_calloc( (count), sizeof( type ) ) ) #define libspectrum_renew( type, mem, count ) \ - ( ( type * ) libspectrum_realloc( (void *)mem, sizeof( type ) * (count) ) ) + ( ( type * ) libspectrum_realloc_n( (void *)mem, (count), sizeof( type ) ) ) /* Attempt to identify a given file */ Modified: trunk/libspectrum/memory.c =================================================================== --- trunk/libspectrum/memory.c 2015-03-02 22:32:05 UTC (rev 5127) +++ trunk/libspectrum/memory.c 2015-03-02 22:35:04 UTC (rev 5128) @@ -46,6 +46,14 @@ } void* +libspectrum_malloc_n( size_t nmemb, size_t size ) +{ + if( nmemb > SIZE_MAX / size ) abort(); + + return libspectrum_malloc( nmemb * size ); +} + +void* libspectrum_calloc( size_t nmemb, size_t size ) { void *ptr; @@ -71,6 +79,14 @@ return ptr; } +void* +libspectrum_realloc_n( void *ptr, size_t nmemb, size_t size ) +{ + if( nmemb > SIZE_MAX / size ) abort(); + + return libspectrum_realloc( ptr, nmemb * size ); +} + void libspectrum_free( void *ptr ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-02 22:39:09
|
Revision: 5129 http://sourceforge.net/p/fuse-emulator/code/5129 Author: zubzero Date: 2015-03-02 22:38:59 +0000 (Mon, 02 Mar 2015) Log Message: ----------- Rename libspectrum_calloc() to libspectrum_malloc0_n() Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/libspectrum.h.in trunk/libspectrum/memory.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-02 22:35:04 UTC (rev 5128) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-02 22:38:59 UTC (rev 5129) @@ -988,3 +988,5 @@ 20150302 memory.c: check for overflow in libspectrum_calloc() (Stuart). 20150302 libspectrum.h.in,memory.c: add libspectrum_{m,re}alloc_n() and use this for libspectrum_{new,renew}() macros (Stuart). +20150302 libspectrum.h.in,memory.c: rename libspectrum_calloc() to + libspectrum_malloc0_n() (Stuart). Modified: trunk/libspectrum/libspectrum.h.in =================================================================== --- trunk/libspectrum/libspectrum.h.in 2015-03-02 22:35:04 UTC (rev 5128) +++ trunk/libspectrum/libspectrum.h.in 2015-03-02 22:38:59 UTC (rev 5129) @@ -144,7 +144,7 @@ WIN32_DLL void* libspectrum_malloc( size_t size ); WIN32_DLL void* libspectrum_malloc_n( size_t nmemb, size_t size ); -WIN32_DLL void* libspectrum_calloc( size_t nmemb, size_t size ); +WIN32_DLL void* libspectrum_malloc0_n( size_t nmemb, size_t size ); WIN32_DLL void* libspectrum_realloc( void *ptr, size_t size ); WIN32_DLL void* libspectrum_realloc_n( void *ptr, size_t nmemb, size_t size ); WIN32_DLL void libspectrum_free( void *ptr ); @@ -155,11 +155,14 @@ ( ( type * ) libspectrum_malloc_n( (count), sizeof( type ) ) ) #define libspectrum_new0( type, count ) \ - ( ( type * ) libspectrum_calloc( (count), sizeof( type ) ) ) + ( ( type * ) libspectrum_malloc0_n( (count), sizeof( type ) ) ) #define libspectrum_renew( type, mem, count ) \ - ( ( type * ) libspectrum_realloc_n( (void *)mem, (count), sizeof( type ) ) ) + ( ( type * ) libspectrum_realloc_n( (void *)mem, (count), sizeof( type ) ) +/* Deprecated */ +#define libspectrum_calloc libspectrum_malloc0_n + /* Attempt to identify a given file */ /* Various types of file we might manage to identify */ Modified: trunk/libspectrum/memory.c =================================================================== --- trunk/libspectrum/memory.c 2015-03-02 22:35:04 UTC (rev 5128) +++ trunk/libspectrum/memory.c 2015-03-02 22:38:59 UTC (rev 5129) @@ -29,6 +29,12 @@ #include "internals.h" +/* We don't want the macro from libspectrum.h */ +#undef libspectrum_calloc + +/* Deprecated, removed from header in favour of macro. */ +void* libspectrum_calloc( size_t nmemb, size_t size ); + libspectrum_malloc_fn_t libspectrum_malloc_fn = malloc; libspectrum_calloc_fn_t libspectrum_calloc_fn = calloc; libspectrum_realloc_fn_t libspectrum_realloc_fn = realloc; @@ -54,7 +60,7 @@ } void* -libspectrum_calloc( size_t nmemb, size_t size ) +libspectrum_malloc0_n( size_t nmemb, size_t size ) { void *ptr; @@ -69,6 +75,12 @@ } void* +libspectrum_calloc( size_t nmemb, size_t size ) +{ + return libspectrum_malloc0_n( nmemb, size ); +} + +void* libspectrum_realloc( void *ptr, size_t size ) { ptr = libspectrum_realloc_fn( ptr, size ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-15 15:50:36
|
Revision: 5137 http://sourceforge.net/p/fuse-emulator/code/5137 Author: zubzero Date: 2015-03-15 15:50:28 +0000 (Sun, 15 Mar 2015) Log Message: ----------- Remove automatic fallback to GLib replacement (now --with-fake-glib) Modified Paths: -------------- trunk/libspectrum/README trunk/libspectrum/configure.ac trunk/libspectrum/hacking/ChangeLog Modified: trunk/libspectrum/README =================================================================== --- trunk/libspectrum/README 2015-03-14 13:23:36 UTC (rev 5136) +++ trunk/libspectrum/README 2015-03-15 15:50:28 UTC (rev 5137) @@ -59,7 +59,7 @@ ./configure --target=powerpc-gekko --host=powerpc-gekko \ --prefix=$DEVKITPPC \ - --without-gcrypt --without-glib --without-libaudiofile + --without-gcrypt --with-fake-glib --without-libaudiofile That is assuming you don't have gcrypt, glib and libaudiofile for the Wii. At the time of writing, those haven't been ported yet. Modified: trunk/libspectrum/configure.ac =================================================================== --- trunk/libspectrum/configure.ac 2015-03-14 13:23:36 UTC (rev 5136) +++ trunk/libspectrum/configure.ac 2015-03-15 15:50:28 UTC (rev 5137) @@ -158,23 +158,23 @@ ) fi -dnl Either find glib or use the replacement -AC_MSG_CHECKING(whether to use glib) -AC_ARG_WITH(glib, -[ --without-glib don't use glib], -if test "$withval" = no; then glib=no; else glib=yes; fi, -glib=yes) -AC_MSG_RESULT($glib) -AS_IF([test "$glib" = yes], [ +dnl Either find GLib or use the replacement +AC_MSG_CHECKING(whether to use internal GLib replacement) +AC_ARG_WITH(fake-glib, +[ --with-fake-glib use internal GLib replacement], +if test "$withval" = no; then myglib=no; else myglib=yes; fi, +myglib=no) +AC_MSG_RESULT($myglib) +AS_IF([test "$myglib" = no], [ PKG_CHECK_MODULES( GLIB, glib-2.0, - AC_DEFINE([HAVE_LIB_GLIB], 1, [Defined if we've got glib]), - glib="no" + AC_DEFINE([HAVE_LIB_GLIB], 1, [Defined if we've got GLib]), + AC_MSG_ERROR([GLib not found]) ) ]) -AM_CONDITIONAL(USE_MYGLIB, test "$glib" = no) +AM_CONDITIONAL(USE_MYGLIB, test "$myglib" = yes) dnl If it appears we're using gcc as our compiler, turn on warnings if test "$ac_cv_c_compiler_gnu" = yes; then Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-14 13:23:36 UTC (rev 5136) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-15 15:50:28 UTC (rev 5137) @@ -990,3 +990,5 @@ for libspectrum_{new,renew}() macros (Stuart). 20150302 libspectrum.h.in,memory.c: rename libspectrum_calloc() to libspectrum_malloc0_n() (Stuart). +20150315 configure.ac: remove automatic fallback to GLib replacement (now + --with-fake-glib) (Stuart). This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-15 15:53:04
|
Revision: 5138 http://sourceforge.net/p/fuse-emulator/code/5138 Author: zubzero Date: 2015-03-15 15:52:57 +0000 (Sun, 15 Mar 2015) Log Message: ----------- Add LIBSPECTRUM_HAS_GLIB_REPLACEMENT macro to libspectrum.h Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/make-perl.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-15 15:50:28 UTC (rev 5137) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-15 15:52:57 UTC (rev 5138) @@ -990,5 +990,6 @@ for libspectrum_{new,renew}() macros (Stuart). 20150302 libspectrum.h.in,memory.c: rename libspectrum_calloc() to libspectrum_malloc0_n() (Stuart). -20150315 configure.ac: remove automatic fallback to GLib replacement (now +20150315 README,configure.ac: remove automatic fallback to GLib replacement (now --with-fake-glib) (Stuart). +20150315 make-perl.c: add LIBSPECTRUM_HAS_GLIB_REPLACEMENT macro (Stuart). Modified: trunk/libspectrum/make-perl.c =================================================================== --- trunk/libspectrum/make-perl.c 2015-03-15 15:50:28 UTC (rev 5137) +++ trunk/libspectrum/make-perl.c 2015-03-15 15:52:57 UTC (rev 5138) @@ -115,11 +115,13 @@ #ifdef HAVE_LIB_GLIB /* #ifdef HAVE_LIB_GLIB */ - printf( " $_ = '';\n\n" ); + printf( " $_ = \"#define LIBSPECTRUM_HAS_GLIB_REPLACEMENT 0\\n\"\n" ); #else /* #ifdef HAVE_LIB_GLIB */ printf( " $_ = << \"CODE\";\n" +"#define LIBSPECTRUM_HAS_GLIB_REPLACEMENT 1\n" +"\n" "#ifndef FALSE\n" "#define FALSE (0)\n" "#endif\n" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-16 13:29:00
|
Revision: 5149 http://sourceforge.net/p/fuse-emulator/code/5149 Author: zubzero Date: 2015-03-16 13:28:53 +0000 (Mon, 16 Mar 2015) Log Message: ----------- configure.ac: always use -Wwrite-strings when using GCC Modified Paths: -------------- trunk/libspectrum/configure.ac trunk/libspectrum/hacking/ChangeLog Modified: trunk/libspectrum/configure.ac =================================================================== --- trunk/libspectrum/configure.ac 2015-03-16 02:21:41 UTC (rev 5148) +++ trunk/libspectrum/configure.ac 2015-03-16 13:28:53 UTC (rev 5149) @@ -178,7 +178,7 @@ dnl If it appears we're using gcc as our compiler, turn on warnings if test "$ac_cv_c_compiler_gnu" = yes; then - CFLAGS="$CFLAGS -Wall" + CFLAGS="$CFLAGS -Wall -Wwrite-strings" dnl And possibly lots of warnings AC_MSG_CHECKING(whether lots of warnings requested) AC_ARG_ENABLE(warnings, @@ -191,7 +191,7 @@ warnings=no) AC_MSG_RESULT($warnings) if test "$warnings" = yes; then - CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Winline -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Waggregate-return -W -Wsign-compare" + CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Winline -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Waggregate-return -W -Wsign-compare" fi fi Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-16 02:21:41 UTC (rev 5148) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-16 13:28:53 UTC (rev 5149) @@ -993,3 +993,4 @@ 20150315 README,configure.ac: remove automatic fallback to GLib replacement (now --with-fake-glib) (Stuart). 20150315 make-perl.c: add LIBSPECTRUM_HAS_GLIB_REPLACEMENT macro (Stuart). +20150316 configure.ac: always use -Wwrite-strings when using GCC (Stuart). This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-16 14:06:12
|
Revision: 5151 http://sourceforge.net/p/fuse-emulator/code/5151 Author: zubzero Date: 2015-03-16 14:06:04 +0000 (Mon, 16 Mar 2015) Log Message: ----------- Define ZLIB_CONST when including <zlib.h> and remove unnecessary cast Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/zlib.c trunk/libspectrum/zxs.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-16 13:35:58 UTC (rev 5150) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-16 14:06:04 UTC (rev 5151) @@ -994,3 +994,5 @@ --with-fake-glib) (Stuart). 20150315 make-perl.c: add LIBSPECTRUM_HAS_GLIB_REPLACEMENT macro (Stuart). 20150316 configure.ac: always use -Wwrite-strings when using GCC (Stuart). +20150316 zlib.c,zxs.c: define ZLIB_CONST when including <zlib.h> and remove cast + used as workaround for discarding of const (Stuart). Modified: trunk/libspectrum/zlib.c =================================================================== --- trunk/libspectrum/zlib.c 2015-03-16 13:35:58 UTC (rev 5150) +++ trunk/libspectrum/zlib.c 2015-03-16 14:06:04 UTC (rev 5151) @@ -38,6 +38,7 @@ #include <unistd.h> #endif /* #ifdef HAVE_UNISTD_H */ +#define ZLIB_CONST #include <zlib.h> #include "internals.h" @@ -86,8 +87,7 @@ /* Use default memory management */ stream.zalloc = Z_NULL; stream.zfree = Z_NULL; stream.opaque = Z_NULL; - /* Cast needed to avoid warning about losing const */ - stream.next_in = (libspectrum_byte*)gzptr; stream.avail_in = gzlength; + stream.next_in = gzptr; stream.avail_in = gzlength; if( gzip_hack ) { Modified: trunk/libspectrum/zxs.c =================================================================== --- trunk/libspectrum/zxs.c 2015-03-16 13:35:58 UTC (rev 5150) +++ trunk/libspectrum/zxs.c 2015-03-16 14:06:04 UTC (rev 5151) @@ -28,6 +28,7 @@ #include <string.h> #ifdef HAVE_ZLIB_H +#define ZLIB_CONST #include <zlib.h> #endif /* #ifdef HAVE_ZLIB_H */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-16 14:21:01
|
Revision: 5153 http://sourceforge.net/p/fuse-emulator/code/5153 Author: zubzero Date: 2015-03-16 14:20:49 +0000 (Mon, 16 Mar 2015) Log Message: ----------- pzx_read: add missing const qualifiers and remove casts Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/pzx_read.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-16 14:12:21 UTC (rev 5152) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-16 14:20:49 UTC (rev 5153) @@ -996,3 +996,4 @@ 20150316 configure.ac: always use -Wwrite-strings when using GCC (Stuart). 20150316 zlib.c,zxs.c: define ZLIB_CONST when including <zlib.h> and remove cast used as workaround for discarding of const (Stuart). +20150316 pzx_read.c: add missing const qualifiers and remove casts (Stuart). Modified: trunk/libspectrum/pzx_read.c =================================================================== --- trunk/libspectrum/pzx_read.c 2015-03-16 14:12:21 UTC (rev 5152) +++ trunk/libspectrum/pzx_read.c 2015-03-16 14:20:49 UTC (rev 5153) @@ -107,8 +107,8 @@ static int info_t_compar(const void *a, const void *b) { - char *key = (char *)a; - struct info_t *test = (struct info_t *)b; + const char *key = a; + const struct info_t *test = b; return strcmp( key, test->id ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-16 14:37:13
|
Revision: 5154 http://sourceforge.net/p/fuse-emulator/code/5154 Author: zubzero Date: 2015-03-16 14:37:11 +0000 (Mon, 16 Mar 2015) Log Message: ----------- Remove autogeneration warning from libspectrum.h.in Modified Paths: -------------- trunk/libspectrum/generate.pl.in trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/libspectrum.h.in Modified: trunk/libspectrum/generate.pl.in =================================================================== --- trunk/libspectrum/generate.pl.in 2015-03-16 14:20:49 UTC (rev 5153) +++ trunk/libspectrum/generate.pl.in 2015-03-16 14:37:11 UTC (rev 5154) @@ -4,6 +4,13 @@ }; +if( /LIBSPECTRUM_AUTOGEN_WARNING/ ) { + $_ = << "CODE"; +/* NB: This file is autogenerated from libspectrum.h.in. Do not edit + unless you know what you're doing */ +CODE +} + if( /LIBSPECTRUM_SNAP_ACCESSORS/ ) { open( DATAFILE, '<' . "${srcdir}/snap_accessors.txt" ) or die "Couldn't open `snap_accessors.txt': $!"; Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-16 14:20:49 UTC (rev 5153) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-16 14:37:11 UTC (rev 5154) @@ -997,3 +997,5 @@ 20150316 zlib.c,zxs.c: define ZLIB_CONST when including <zlib.h> and remove cast used as workaround for discarding of const (Stuart). 20150316 pzx_read.c: add missing const qualifiers and remove casts (Stuart). +20150316 generate.pl.in,libspectrum.h.in: remove autogeneration warning from + libspectrum.h.in (Stuart). Modified: trunk/libspectrum/libspectrum.h.in =================================================================== --- trunk/libspectrum/libspectrum.h.in 2015-03-16 14:20:49 UTC (rev 5153) +++ trunk/libspectrum/libspectrum.h.in 2015-03-16 14:37:11 UTC (rev 5154) @@ -23,8 +23,7 @@ */ -/* NB: This file is autogenerated from libspectrum.h.in. Do not edit - unless you know what you're doing */ +LIBSPECTRUM_AUTOGEN_WARNING #ifndef LIBSPECTRUM_LIBSPECTRUM_H #define LIBSPECTRUM_LIBSPECTRUM_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-16 14:38:57
|
Revision: 5155 http://sourceforge.net/p/fuse-emulator/code/5155 Author: zubzero Date: 2015-03-16 14:38:55 +0000 (Mon, 16 Mar 2015) Log Message: ----------- libspectrum.txt: add missing line break Modified Paths: -------------- trunk/libspectrum/doc/libspectrum.txt trunk/libspectrum/hacking/ChangeLog Modified: trunk/libspectrum/doc/libspectrum.txt =================================================================== --- trunk/libspectrum/doc/libspectrum.txt 2015-03-16 14:37:11 UTC (rev 5154) +++ trunk/libspectrum/doc/libspectrum.txt 2015-03-16 14:38:55 UTC (rev 5155) @@ -1038,7 +1038,8 @@ The following two blocks are defined in the PZX format -LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE A run-length encoded list of pulses with polarity specified +LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE A run-length encoded list of pulses + with polarity specified LIBSPECTRUM_TAPE_BLOCK_DATA_BLOCK A block of data without pilot or sync pulses with bit encoding and polarity specified Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-16 14:37:11 UTC (rev 5154) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-16 14:38:55 UTC (rev 5155) @@ -999,3 +999,4 @@ 20150316 pzx_read.c: add missing const qualifiers and remove casts (Stuart). 20150316 generate.pl.in,libspectrum.h.in: remove autogeneration warning from libspectrum.h.in (Stuart). +20150316 doc/libspectrum.txt: add missing line break (Stuart). This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-16 23:44:37
|
Revision: 5162 http://sourceforge.net/p/fuse-emulator/code/5162 Author: zubzero Date: 2015-03-16 23:44:35 +0000 (Mon, 16 Mar 2015) Log Message: ----------- Store PC-1 for all snapshot formats whilst in the halted state Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/snapshot.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-16 23:42:32 UTC (rev 5161) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-16 23:44:35 UTC (rev 5162) @@ -1000,3 +1000,5 @@ 20150316 generate.pl.in,libspectrum.h.in: remove autogeneration warning from libspectrum.h.in (Stuart). 20150316 doc/libspectrum.txt: add missing line break (Stuart). +20150316 snapshot.c: store PC-1 for all snapshot formats whilst in the halted + state (Stuart). Modified: trunk/libspectrum/snapshot.c =================================================================== --- trunk/libspectrum/snapshot.c 2015-03-16 23:42:32 UTC (rev 5161) +++ trunk/libspectrum/snapshot.c 2015-03-16 23:44:35 UTC (rev 5162) @@ -361,6 +361,13 @@ return LIBSPECTRUM_ERROR_LOGIC; } + /* Sadly, virtually all emulators handle saving of PC incorrectly when + * executing a HALT instruction, so it's easiest to deal with this just + * once, so that it affects all snapshot formats. */ + if( libspectrum_snap_halted( snap ) ) { + libspectrum_snap_set_pc( snap, libspectrum_snap_pc( snap ) + 1 ); + } + libspectrum_free( new_buffer ); return error; } @@ -373,6 +380,7 @@ { libspectrum_class_t class; libspectrum_error error; + libspectrum_word orig_pc; error = libspectrum_identify_class( &class, type ); if( error ) return error; @@ -383,17 +391,29 @@ return LIBSPECTRUM_ERROR_INVALID; } + /* Sadly, virtually all emulators handle saving of PC incorrectly when + * executing a HALT instruction, so it's easiest to deal with this just + * once, so that it affects all snapshot formats. */ + orig_pc = libspectrum_snap_pc( snap ); + if( libspectrum_snap_halted( snap ) ) { + libspectrum_snap_set_pc( snap, orig_pc - 1 ); + } + switch( type ) { case LIBSPECTRUM_ID_SNAPSHOT_SNA: - return libspectrum_sna_write( buffer, length, out_flags, snap, in_flags ); + error = libspectrum_sna_write( buffer, length, out_flags, snap, in_flags ); + break; case LIBSPECTRUM_ID_SNAPSHOT_SZX: - return libspectrum_szx_write( buffer, length, out_flags, snap, creator, - in_flags ); + error = libspectrum_szx_write( buffer, length, out_flags, snap, creator, + in_flags ); + break; case LIBSPECTRUM_ID_SNAPSHOT_Z80: - return libspectrum_z80_write2( buffer, length, out_flags, snap, in_flags ); + error = libspectrum_z80_write2( buffer, length, out_flags, snap, + in_flags ); + break; default: libspectrum_print_error( LIBSPECTRUM_ERROR_UNKNOWN, @@ -401,6 +421,11 @@ return LIBSPECTRUM_ERROR_UNKNOWN; } + + /* Put back the correct value of PC, in case snap is needed again */ + libspectrum_snap_set_pc( snap, orig_pc ); + + return error; } /* Given a 48K memory dump `data', place it into the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-03-19 15:08:49
|
Revision: 5184 http://sourceforge.net/p/fuse-emulator/code/5184 Author: zubzero Date: 2015-03-19 15:08:41 +0000 (Thu, 19 Mar 2015) Log Message: ----------- Const and static cleanups Modified Paths: -------------- trunk/libspectrum/crypto.c trunk/libspectrum/csw.c trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/internals.h trunk/libspectrum/libspectrum.c trunk/libspectrum/pzx_read.c trunk/libspectrum/rzx.c trunk/libspectrum/szx.c trunk/libspectrum/tzx_read.c Modified: trunk/libspectrum/crypto.c =================================================================== --- trunk/libspectrum/crypto.c 2015-03-19 14:47:11 UTC (rev 5183) +++ trunk/libspectrum/crypto.c 2015-03-19 15:08:41 UTC (rev 5184) @@ -31,12 +31,12 @@ #include "internals.h" -static const char *private_key_format = +static const char * const private_key_format = "(key-data (private-key (dsa (p %m) (q %m) (g %m) (y %m) (x %m))))"; -static const char *public_key_format = +static const char * const public_key_format = "(key-data (public-key (dsa (p %m) (q %m) (g %m) (y %m))))"; -static const char *hash_format = "(data (flags raw) (value %m))"; -static const char *signature_format = "(sig-val (dsa (r %m) (s %m)))"; +static const char * const hash_format = "(data (flags raw) (value %m))"; +static const char * const signature_format = "(sig-val (dsa (r %m) (s %m)))"; #define HASH_ALGORITHM GCRY_MD_SHA1 #define MPI_COUNT 5 Modified: trunk/libspectrum/csw.c =================================================================== --- trunk/libspectrum/csw.c 2015-03-19 14:47:11 UTC (rev 5183) +++ trunk/libspectrum/csw.c 2015-03-19 15:08:41 UTC (rev 5184) @@ -31,7 +31,7 @@ #include "tape_block.h" /* The .csw file signature (first 23 bytes) */ -const char *libspectrum_csw_signature = "Compressed Square Wave\x1a"; +static const char * const csw_signature = "Compressed Square Wave\x1a"; libspectrum_error libspectrum_csw_read( libspectrum_tape *tape, @@ -42,11 +42,11 @@ int compressed; - size_t signature_length = strlen( libspectrum_csw_signature ); + size_t signature_length = strlen( csw_signature ); if( length < signature_length + 2 ) goto csw_short; - if( memcmp( libspectrum_csw_signature, buffer, signature_length ) ) { + if( memcmp( csw_signature, buffer, signature_length ) ) { libspectrum_print_error( LIBSPECTRUM_ERROR_SIGNATURE, "libspectrum_csw_read: wrong signature" ); return LIBSPECTRUM_ERROR_SIGNATURE; @@ -320,12 +320,12 @@ libspectrum_byte *ptr = *buffer; - size_t signature_length = strlen( libspectrum_csw_signature ); + size_t signature_length = strlen( csw_signature ); /* First, write the .csw signature and the rest of the header */ libspectrum_make_room( buffer, signature_length + 29, &ptr, length ); - memcpy( ptr, libspectrum_csw_signature, signature_length ); + memcpy( ptr, csw_signature, signature_length ); ptr += signature_length; *ptr++ = 2; /* Major version number */ Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-03-19 14:47:11 UTC (rev 5183) +++ trunk/libspectrum/hacking/ChangeLog 2015-03-19 15:08:41 UTC (rev 5184) @@ -1002,3 +1002,5 @@ 20150316 doc/libspectrum.txt: add missing line break (Stuart). 20150316 snapshot.c: store PC-1 for all snapshot formats whilst in the halted state (Stuart). +20150318 crypto.c,csw.c,internals.h,libspectrum.c,pzx_read.c,rzx.c,szx.c, + tzx_read.c: const and static cleanups (Stuart). Modified: trunk/libspectrum/internals.h =================================================================== --- trunk/libspectrum/internals.h 2015-03-19 14:47:11 UTC (rev 5183) +++ trunk/libspectrum/internals.h 2015-03-19 15:08:41 UTC (rev 5184) @@ -130,7 +130,7 @@ /* The TZX file signature */ -extern const char *libspectrum_tzx_signature; +extern const char * const libspectrum_tzx_signature; /* Convert a 48K memory dump into separate RAM pages */ Modified: trunk/libspectrum/libspectrum.c =================================================================== --- trunk/libspectrum/libspectrum.c 2015-03-19 14:47:11 UTC (rev 5183) +++ trunk/libspectrum/libspectrum.c 2015-03-19 15:08:41 UTC (rev 5184) @@ -36,7 +36,7 @@ #include <gcrypt.h> /* The version of libgcrypt that we need */ -static const char *MIN_GCRYPT_VERSION = "1.1.42"; +static const char * const MIN_GCRYPT_VERSION = "1.1.42"; #endif /* #ifdef HAVE_GCRYPT_H */ Modified: trunk/libspectrum/pzx_read.c =================================================================== --- trunk/libspectrum/pzx_read.c 2015-03-19 14:47:11 UTC (rev 5183) +++ trunk/libspectrum/pzx_read.c 2015-03-19 15:08:41 UTC (rev 5184) @@ -83,7 +83,7 @@ /* TODO: an extension to be similar to the TZX Custom Block Picture type */ #define PZX_INLAY "inly" -static const char *signature = PZX_HEADER; +static const char * const signature = PZX_HEADER; static const size_t signature_length = 4; static libspectrum_error Modified: trunk/libspectrum/rzx.c =================================================================== --- trunk/libspectrum/rzx.c 2015-03-19 14:47:11 UTC (rev 5183) +++ trunk/libspectrum/rzx.c 2015-03-19 15:08:41 UTC (rev 5184) @@ -173,7 +173,7 @@ libspectrum_rzx_dsa_key *key ); /* The signature used to identify .rzx files */ -const char *rzx_signature = "RZX!"; +static const char * const rzx_signature = "RZX!"; /* The IN count used to signify 'repeat last frame' */ const libspectrum_word libspectrum_rzx_repeat_frame = 0xffff; Modified: trunk/libspectrum/szx.c =================================================================== --- trunk/libspectrum/szx.c 2015-03-19 14:47:11 UTC (rev 5183) +++ trunk/libspectrum/szx.c 2015-03-19 15:08:41 UTC (rev 5184) @@ -61,12 +61,12 @@ } szx_machine_type; -static const char *signature = "ZXST"; +static const char * const signature = "ZXST"; static const size_t signature_length = 4; static const libspectrum_byte ZXSTMF_ALTERNATETIMINGS = 1; -static const char *libspectrum_string = "libspectrum: "; +static const char * const libspectrum_string = "libspectrum: "; static const libspectrum_byte SZX_VERSION_MAJOR = 1; static const libspectrum_byte SZX_VERSION_MINOR = 5; Modified: trunk/libspectrum/tzx_read.c =================================================================== --- trunk/libspectrum/tzx_read.c 2015-03-19 14:47:11 UTC (rev 5183) +++ trunk/libspectrum/tzx_read.c 2015-03-19 15:08:41 UTC (rev 5184) @@ -33,7 +33,7 @@ #include "internals.h" /* The .tzx file signature (first 8 bytes) */ -const char *libspectrum_tzx_signature = "ZXTape!\x1a"; +const char * const libspectrum_tzx_signature = "ZXTape!\x1a"; /*** Local function prototypes ***/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-04-18 12:23:49
|
Revision: 5200 http://sourceforge.net/p/fuse-emulator/code/5200 Author: zubzero Date: 2015-04-18 12:23:47 +0000 (Sat, 18 Apr 2015) Log Message: ----------- Fix compilation on systems without stdint.h Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/internals.h Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-04-12 22:07:17 UTC (rev 5199) +++ trunk/libspectrum/hacking/ChangeLog 2015-04-18 12:23:47 UTC (rev 5200) @@ -1004,3 +1004,4 @@ state (Stuart). 20150318 crypto.c,csw.c,internals.h,libspectrum.c,pzx_read.c,rzx.c,szx.c, tzx_read.c: const and static cleanups (Stuart). +20150418 internals.h: fix compilation on systems without stdint.h (Stuart). Modified: trunk/libspectrum/internals.h =================================================================== --- trunk/libspectrum/internals.h 2015-04-12 22:07:17 UTC (rev 5199) +++ trunk/libspectrum/internals.h 2015-04-18 12:23:47 UTC (rev 5200) @@ -77,6 +77,11 @@ (sizeof(a) / sizeof(*a)) \ + MUST_BE_ARRAY(a)) +/* C90 lacks SIZE_MAX. size_t is always unsigned so this is safe. */ +#ifndef SIZE_MAX +#define SIZE_MAX (~(size_t)0) +#endif + /* VC6 lacks M_LN2, and VS2003+ require _USE_MATH_DEFINES defined before math.h */ #ifndef M_LN2 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-05-06 22:40:54
|
Revision: 5234 http://sourceforge.net/p/fuse-emulator/code/5234 Author: zubzero Date: 2015-05-06 22:40:52 +0000 (Wed, 06 May 2015) Log Message: ----------- libspectrum.h: add missing compatibility comments Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/libspectrum.h.in Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-05-06 10:32:09 UTC (rev 5233) +++ trunk/libspectrum/hacking/ChangeLog 2015-05-06 22:40:52 UTC (rev 5234) @@ -1005,3 +1005,4 @@ 20150318 crypto.c,csw.c,internals.h,libspectrum.c,pzx_read.c,rzx.c,szx.c, tzx_read.c: const and static cleanups (Stuart). 20150418 internals.h: fix compilation on systems without stdint.h (Stuart). +20150506 libspectrum.h.in: add missing compatibility comments (Stuart). Modified: trunk/libspectrum/libspectrum.h.in =================================================================== --- trunk/libspectrum/libspectrum.h.in 2015-05-06 10:32:09 UTC (rev 5233) +++ trunk/libspectrum/libspectrum.h.in 2015-05-06 22:40:52 UTC (rev 5234) @@ -231,8 +231,12 @@ LIBSPECTRUM_ID_DISK_SAD, /* .sad generic disk image */ LIBSPECTRUM_ID_DISK_TD0, /* .td0 generic disk image */ + /* Below here, present only in 1.0.0 and later */ + LIBSPECTRUM_ID_DISK_OPD, /* .opu/.opd Opus Discovery disk image */ + /* Below here, present only in 1.1.0 and later */ + LIBSPECTRUM_ID_TAPE_PZX, /* PZX tape image */ LIBSPECTRUM_ID_AUX_POK, /* POKE file */ @@ -273,6 +277,8 @@ LIBSPECTRUM_CLASS_DISK_GENERIC, /* generic disk image */ + /* Below here, present only in 1.1.0 and later */ + LIBSPECTRUM_CLASS_AUXILIARY, /* auxiliary supported file */ } libspectrum_class_t; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zu...@us...> - 2015-05-06 23:13:00
|
Revision: 5235 http://sourceforge.net/p/fuse-emulator/code/5235 Author: zubzero Date: 2015-05-06 23:12:57 +0000 (Wed, 06 May 2015) Log Message: ----------- Add Didaktik disk class and image format (part of patch #330) (Gergely Szasz) Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/libspectrum.c trunk/libspectrum/libspectrum.h.in Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2015-05-06 22:40:52 UTC (rev 5234) +++ trunk/libspectrum/hacking/ChangeLog 2015-05-06 23:12:57 UTC (rev 5235) @@ -1006,3 +1006,5 @@ tzx_read.c: const and static cleanups (Stuart). 20150418 internals.h: fix compilation on systems without stdint.h (Stuart). 20150506 libspectrum.h.in: add missing compatibility comments (Stuart). +20150507 libspectrum.{c,h.in}: add Didaktik disk class and image format (part of + patch #331) (Gergely Szasz). Modified: trunk/libspectrum/libspectrum.c =================================================================== --- trunk/libspectrum/libspectrum.c 2015-05-06 22:40:52 UTC (rev 5234) +++ trunk/libspectrum/libspectrum.c 2015-05-06 23:12:57 UTC (rev 5235) @@ -566,6 +566,9 @@ { LIBSPECTRUM_ID_DISK_OPD, "opd", 3, NULL, 0, 0, 0 }, { LIBSPECTRUM_ID_DISK_OPD, "opu", 3, NULL, 0, 0, 0 }, + { LIBSPECTRUM_ID_DISK_D80, "d80", 3, NULL, 0, 0, 0 }, + { LIBSPECTRUM_ID_DISK_D80, "d40", 3, NULL, 0, 0, 0 }, + { LIBSPECTRUM_ID_AUX_POK, "pok", 3, NULL, 0, 0, 0 }, { -1, NULL, 0, NULL, 0, 0, 0 }, /* End marker */ @@ -693,6 +696,9 @@ case LIBSPECTRUM_ID_DISK_OPD: *libspectrum_class = LIBSPECTRUM_CLASS_DISK_OPUS; return 0; + case LIBSPECTRUM_ID_DISK_D80: + *libspectrum_class = LIBSPECTRUM_CLASS_DISK_DIDAKTIK; return 0; + case LIBSPECTRUM_ID_DISK_SCL: case LIBSPECTRUM_ID_DISK_TRD: *libspectrum_class = LIBSPECTRUM_CLASS_DISK_TRDOS; return 0; Modified: trunk/libspectrum/libspectrum.h.in =================================================================== --- trunk/libspectrum/libspectrum.h.in 2015-05-06 22:40:52 UTC (rev 5234) +++ trunk/libspectrum/libspectrum.h.in 2015-05-06 23:12:57 UTC (rev 5235) @@ -241,6 +241,10 @@ LIBSPECTRUM_ID_AUX_POK, /* POKE file */ + /* Below here, present only in 1.2.0 and later */ + + LIBSPECTRUM_ID_DISK_D80, /* .d80/.d40 Didaktik disk image */ + } libspectrum_id_t; /* And 'classes' of file */ @@ -281,6 +285,10 @@ LIBSPECTRUM_CLASS_AUXILIARY, /* auxiliary supported file */ + /* Below here, present only in 1.2.0 and later */ + + LIBSPECTRUM_CLASS_DISK_DIDAKTIK, /* Didaktik disk */ + } libspectrum_class_t; WIN32_DLL libspectrum_error This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |