Bugfix: use memmove() if source and destination range can overlap (found with valgrind).

This commit is contained in:
Volker Ruppert 2014-12-14 18:53:16 +00:00
parent 902ed3f90b
commit f35b9b23c8
4 changed files with 4 additions and 4 deletions

View File

@ -3164,7 +3164,7 @@ void bx_hard_drive_c::init_mode_sense_single(Bit8u channel, const void* src, int
controller->buffer[7] = 0; // reserved
// Data
memcpy(controller->buffer + 8, src, size);
memmove(controller->buffer + 8, src, size);
}
void BX_CPP_AttrRegparmN(1)

View File

@ -310,7 +310,7 @@ void bx_pci_ide_c::timer()
// To avoid buffer overflow reset buffer pointers and copy data if necessary
count = BX_PIDE_THIS s.bmdma[channel].buffer_top - BX_PIDE_THIS s.bmdma[channel].buffer_idx;
if (count > 0) {
memcpy(BX_PIDE_THIS s.bmdma[channel].buffer, BX_PIDE_THIS s.bmdma[channel].buffer_idx, count);
memmove(BX_PIDE_THIS s.bmdma[channel].buffer, BX_PIDE_THIS s.bmdma[channel].buffer_idx, count);
}
BX_PIDE_THIS s.bmdma[channel].buffer_top = BX_PIDE_THIS s.bmdma[channel].buffer + count;
BX_PIDE_THIS s.bmdma[channel].buffer_idx = BX_PIDE_THIS s.bmdma[channel].buffer;

View File

@ -1328,7 +1328,7 @@ Bit32u bx_sb16_c::dsp_adc_handler(Bit32u buflen)
len = DSP.dma.chunkcount - DSP.dma.chunkindex;
if (len > 0) {
memcpy(DSP.dma.chunk, DSP.dma.chunk+DSP.dma.chunkindex, len);
memmove(DSP.dma.chunk, DSP.dma.chunk+DSP.dma.chunkindex, len);
DSP.dma.chunkcount = len;
}
DSP.dma.chunkindex = 0;

View File

@ -310,7 +310,7 @@ int bx_sound_alsa_c::alsa_pcm_write()
BX_ERROR(("ALSA: short write, write %d frames", ret));
}
alsa_pcm[0].audio_bufsize -= alsa_pcm[0].alsa_bufsize;
memcpy(audio_buffer[0], audio_buffer[0]+alsa_pcm[0].alsa_bufsize, alsa_pcm[0].audio_bufsize);
memmove(audio_buffer[0], audio_buffer[0]+alsa_pcm[0].alsa_bufsize, alsa_pcm[0].audio_bufsize);
}
if ((alsa_pcm[0].audio_bufsize == 0) && (alsa_pcm[0].buffer != NULL)) {
free(alsa_pcm[0].buffer);