[AD] Bug in unstable developers release, sound.c

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


I have come across a bug in the unstable developers release stream (at least
4.1.4-4.1.9) in the file src/sound.c.

In the function 'load_wav' (line 951 of the 4.1.9 source), a signed short is
compared against EOF, and will prematurely stop if it encounters valid data
of -1. This only occurs on 16 bit data. Also, in line 944, the result of a
'pack_fread' is compared to the wrong variable, though it would only matter
on a truncated stereo 8 bit wav file.

I have included a context diff below, with a fix and speedup for 16 bit data

PS

The stable releases are unaffected

Regards John Holden

*** OLDsound.c	2003-05-21 12:47:37.000000000 +1000
--- sound.c	2003-05-21 14:03:16.000000000 +1000
***************
*** 890,896 ****
     int freq = 22050;
     int bits = 8;
     int channels = 1;
!    int s;
     SAMPLE *spl = NULL;
     ASSERT(filename);
  
--- 890,896 ----
     int freq = 22050;
     int bits = 8;
     int channels = 1;
!    signed short *p;
     SAMPLE *spl = NULL;
     ASSERT(filename);
  
***************
*** 940,962 ****
  	 spl = create_sample(bits, ((channels == 2) ? TRUE : FALSE), freq, len);
  
  	 if (spl) {
! 	    if (bits == 8) {
! 	       if (pack_fread(spl->data, length, f) < len) {
  		  destroy_sample(spl);
  		  spl = NULL;
! 	       }
  	    }
! 	    else {
! 	       for (i=0; i<len*channels; i++) {
! 		  if ((s = pack_igetw(f)) == EOF) {
! 		     destroy_sample(spl);
! 		     spl = NULL;
! 		     break;
! 		  }
! 		  ((signed short *)spl->data)[i] = (signed short)s^0x8000;
! 	       }
  	    }
- 
  	    length = 0;
  	 }
        }
--- 940,956 ----
  	 spl = create_sample(bits, ((channels == 2) ? TRUE : FALSE), freq, len);
  
  	 if (spl) {
! 	    if (pack_fread(spl->data, length, f) < length) {
  		  destroy_sample(spl);
  		  spl = NULL;
! 		  goto getout;
  	    }
! 	    if(bits == 16) {
! 		p = (unsigned short *)spl->data;
! 		i = length / 2;
! 		while(i--)
! 			*p++ ^= 0x8000;
  	    }
  	    length = 0;
  	 }
        }




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/