mirror of
https://github.com/libretro/fuse-libretro.git
synced 2026-11-07 10:36:03 -10:00
libspectrum: avoid log(0) when a TZX 0x19 data alphabet is empty
bits_per_symbol for a Generalised Data Block (TZX ID 0x19) was computed as ceil( log( symbols_in_table ) / M_LN2 ) without guarding symbols_in_table == 0, so an empty data alphabet evaluated log(0) (undefined) and cast the resulting -inf to int. Compute 0 bits directly in that case; an empty alphabet carries no data symbols, so downstream data_count is 0 and the existing bounds check is unaffected. The one-symbol case still yields 0 bits, matching the TZX specification.
This commit is contained in:
1 parent
24fe44eace
commit
08ffef072d
1 file changed
+5
-1
@@ -635,7 +635,11 @@ tzx_read_generalised_data( libspectrum_tape *tape,
|
||||
|
||||
symbol_count2 = libspectrum_tape_generalised_data_symbol_table_symbols_in_table( table );
|
||||
|
||||
bits_per_symbol = ceil( log( symbol_count2 ) / M_LN2 );
|
||||
/* ceil( log2( n ) ) bits are needed to select one of n symbols. Guard
|
||||
against log( 0 ), which is undefined; an empty alphabet needs no bits
|
||||
(and, per the symbol-table parameter parsing, implies no data symbols). */
|
||||
bits_per_symbol = symbol_count2 ?
|
||||
(int) ceil( log( symbol_count2 ) / M_LN2 ) : 0;
|
||||
|
||||
libspectrum_tape_block_set_bits_per_data_symbol( block, bits_per_symbol );
|
||||
|
||||
|
||||
Reference in new issue
Block a user