From ed2be653119b5c19f131239a429d021820a7a0a8 Mon Sep 17 00:00:00 2001 From: eviltypeguy Date: Wed, 30 Jan 2002 06:35:22 +0000 Subject: [PATCH] Fix for memset glibc bug crash (why would it read from PROT_WRITE only memory? silly thing...) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@1447 d7cf8633-e32d-0410-b094-e92efae38249 --- snd_dma.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/snd_dma.c b/snd_dma.c index aa51cbfd..e68e9669 100644 --- a/snd_dma.c +++ b/snd_dma.c @@ -617,7 +617,16 @@ void S_ClearBuffer (void) else #endif { - memset(shm->buffer, clear, shm->samples * shm->samplebits/8); + int setsize = shm->samples * shm->samplebits / 8; + char *buf = shm->buffer; + + while (setsize--) + *buf++ = 0; + +// on i586/i686 optimized versions of glibc, glibc *wrongly* IMO, +// reads the memory area before writing to it causing a seg fault +// since the memory is PROT_WRITE only and not PROT_READ|PROT_WRITE +// memset(shm->buffer, clear, shm->samples * shm->samplebits/8); } } -- 2.39.2