From 5e4265ba8a8af42b33b0af4d40285536233b4506 Mon Sep 17 00:00:00 2001 From: Bryce Denney Date: Sat, 9 Jun 2001 01:30:20 +0000 Subject: [PATCH] - applied patch.sb16-ftell. Instead of using fgetpos which returns an fpos_t, use ftell which returns an int. Without the patch, Bochs gets an fpos_t and assumes it is an integer type, but on some systems (like linux with newer glibc libraries) this assumption is wrong. Malte Cornils first reported this bug, and he warned me that ftell may not be portable to some platforms which treat binary and ascii streams differently. I haven't found any alternative yet. --- bochs/iodev/sb16.cc | 16 ++++----- bochs/patches/patch.sb16-ftell | 63 ---------------------------------- 2 files changed, 8 insertions(+), 71 deletions(-) delete mode 100644 bochs/patches/patch.sb16-ftell diff --git a/bochs/iodev/sb16.cc b/bochs/iodev/sb16.cc index 6c3bf5d3d..2378ba980 100644 --- a/bochs/iodev/sb16.cc +++ b/bochs/iodev/sb16.cc @@ -2781,7 +2781,6 @@ void bx_sb16_c::writedeltatime(Bit32u deltatime) void bx_sb16_c::finishmidifile() { - fpos_t tracklen; struct { Bit8u delta, statusbyte, metaevent, length; } metatrackend = { 0, 0xff, 0x2f, 0 }; @@ -2789,19 +2788,20 @@ void bx_sb16_c::finishmidifile() // Meta event track end (0xff 0x2f 0x00) plus leading delta time fwrite(&metatrackend, 1, sizeof metatrackend, MIDIDATA ); - fgetpos(MIDIDATA, &tracklen); + Bit32u tracklen = ftell(MIDIDATA); + if (tracklen < 0) + BX_PANIC (("ftell failed in finishmidifile")); + if (tracklen < 22) + BX_PANIC (("finishmidifile with track length too short")); tracklen -= 22; // subtract the midi file and track header - fseek(MIDIDATA, 22 - 4, SEEK_SET); - - // value has to be in big endian + // value has to be in big endian #ifdef BX_LITTLE_ENDIAN tracklen = (tracklen << 24) | (tracklen >> 24) | - ((tracklen & 0x00ff0000) >> 8) | - ((tracklen & 0x0000ff00) << 8); + ((tracklen & 0x00ff0000) >> 8) | + ((tracklen & 0x0000ff00) << 8); #endif fwrite(&tracklen, 4, 1, MIDIDATA); - return; } diff --git a/bochs/patches/patch.sb16-ftell b/bochs/patches/patch.sb16-ftell deleted file mode 100644 index 3e0a49c2a..000000000 --- a/bochs/patches/patch.sb16-ftell +++ /dev/null @@ -1,63 +0,0 @@ ----------------------------------------------------------------------- -Patch name: patch.sb16-ftell -Author: Bryce Denney -Date: Tue Jun 5 20:13:23 EDT 2001 - -Detailed description: - [ #425640 ] sb16 assumes fpos_t is long int - Use ftell since it returns an int, rather than fgetpos which returns - a fpos_t. Without the patch, Bochs gets an fpos_t and assumes it - is an integer type, but on some systems (like linux with newer - glibc libraries) this assumption is not valid. - - Malte Cornils first reported this bug, and he - warned me that ftell is not portable to some platforms, and that's - why I haven't checked in the change. - -Apply patch to: - current CVS -Instructions: - To patch, go to main bochs directory. - Type "patch -p0 < THIS_PATCH_FILE". ----------------------------------------------------------------------- -RCS file: /cvsroot/bochs/bochs/iodev/sb16.cc,v -retrieving revision 1.7 -diff -u -r1.7 sb16.cc ---- iodev/sb16.cc 2001/05/30 18:56:01 1.7 -+++ iodev/sb16.cc 2001/06/06 00:12:58 -@@ -2781,7 +2781,6 @@ - - void bx_sb16_c::finishmidifile() - { -- fpos_t tracklen; - struct { - Bit8u delta, statusbyte, metaevent, length; - } metatrackend = { 0, 0xff, 0x2f, 0 }; -@@ -2789,19 +2788,20 @@ - // Meta event track end (0xff 0x2f 0x00) plus leading delta time - fwrite(&metatrackend, 1, sizeof metatrackend, MIDIDATA ); - -- fgetpos(MIDIDATA, &tracklen); -+ Bit32u tracklen = ftell(MIDIDATA); -+ if (tracklen < 0) -+ BX_PANIC (("ftell failed in finishmidifile")); -+ if (tracklen < 22) -+ BX_PANIC (("finishmidifile with track length too short")); - tracklen -= 22; // subtract the midi file and track header -- - fseek(MIDIDATA, 22 - 4, SEEK_SET); -- -- // value has to be in big endian -+ // value has to be in big endian - #ifdef BX_LITTLE_ENDIAN - tracklen = (tracklen << 24) | (tracklen >> 24) | -- ((tracklen & 0x00ff0000) >> 8) | -- ((tracklen & 0x0000ff00) << 8); -+ ((tracklen & 0x00ff0000) >> 8) | -+ ((tracklen & 0x0000ff00) << 8); - #endif - fwrite(&tracklen, 4, 1, MIDIDATA); -- - return; - } -