ref: 955a62fe39dcc3c475e6a44d50e9f3f62a7b05aa
parent: 38de7eaca1fa15e005bc0065adc7019dfaedae38
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Fri Oct 11 23:41:00 EDT 2024
memcpy -> memmove everywhere memcpy on the same buffer managed to cause a crash in loopback network logic. Just get rid of all cases altogether.
--- a/cl_parse.c
+++ b/cl_parse.c
@@ -138,7 +138,7 @@
// read messages from server, should just be nops
old = net_message;
- memcpy (olddata, net_message.data, net_message.cursize);
+ memmove (olddata, net_message.data, net_message.cursize);
do
{
@@ -160,7 +160,7 @@
} while (ret);
net_message = old;
- memcpy (net_message.data, olddata, net_message.cursize);
+ memmove (net_message.data, olddata, net_message.cursize);
// check time
time = dtime ();
@@ -511,7 +511,7 @@
fatal ("CL_NewTranslation: slot > cl.maxclients");
dest = cl.scores[slot].translations;
source = vid.colormap;
- memcpy(dest, vid.colormap, sizeof cl.scores[slot].translations);
+ memmove(dest, vid.colormap, sizeof cl.scores[slot].translations);
top = cl.scores[slot].colors & 0xf0;
bottom = (cl.scores[slot].colors &15)<<4;
@@ -518,13 +518,13 @@
for (i=0 ; i<VID_GRADES ; i++, dest += 256, source+=256)
{
if(top < 128) // the artists made some backwards ranges. sigh.
- memcpy (dest + TOP_RANGE, source + top, 16*sizeof(pixel_t));
+ memmove (dest + TOP_RANGE, source + top, 16*sizeof(pixel_t));
else
for (j=0 ; j<16 ; j++)
dest[TOP_RANGE+j] = source[top+15-j];
if(bottom < 128)
- memcpy (dest + BOTTOM_RANGE, source + bottom, 16*sizeof(pixel_t));
+ memmove (dest + BOTTOM_RANGE, source + bottom, 16*sizeof(pixel_t));
else
for (j=0 ; j<16 ; j++)
dest[BOTTOM_RANGE+j] = source[bottom+15-j];
--- a/cmd.c
+++ b/cmd.c
@@ -94,7 +94,7 @@
if (templen)
{
temp = Z_Malloc (templen);
- memcpy(temp, cmd_text.data, templen);
+ memmove(temp, cmd_text.data, templen);
SZ_Clear (&cmd_text);
}
@@ -138,7 +138,7 @@
}
- memcpy(line, text, i);
+ memmove(line, text, i);
line[i] = 0;
// delete the text from the command buffer and move remaining commands down
--- a/colormatrix.c
+++ b/colormatrix.c
@@ -105,17 +105,17 @@
void
cminit(void)
{
- memcpy(cm, cm0, sizeof(cm));
+ memmove(cm, cm0, sizeof(cm));
Cvar_RegisterVariable(&v_brightness);
v_brightness.cb = cmcvarcb;
- memcpy(cmbrightness, cmf0, sizeof(cmf0));
+ memmove(cmbrightness, cmf0, sizeof(cmf0));
Cvar_RegisterVariable(&v_contrast);
v_contrast.cb = cmcvarcb;
- memcpy(cmcontrast, cmf0, sizeof(cmf0));
+ memmove(cmcontrast, cmf0, sizeof(cmf0));
Cvar_RegisterVariable(&v_saturation);
v_saturation.cb = cmcvarcb;
- memcpy(cmsaturation, cmf0, sizeof(cmf0));
+ memmove(cmsaturation, cmf0, sizeof(cmf0));
}
--- a/common.c
+++ b/common.c
@@ -404,7 +404,7 @@
void
SZ_Write(sizebuf_t *buf, void *data, int length)
{
- memcpy(SZ_GetSpace(buf, length), data, length);
+ memmove(SZ_GetSpace(buf, length), data, length);
}
void
@@ -415,9 +415,9 @@
len = strlen(data)+1;
if(buf->data[buf->cursize-1])
- memcpy(SZ_GetSpace(buf, len), data, len); // no trailing 0
+ memmove(SZ_GetSpace(buf, len), data, len); // no trailing 0
else
- memcpy((byte *)SZ_GetSpace(buf, len-1)-1, data, len); // write over trailing 0
+ memmove((byte *)SZ_GetSpace(buf, len-1)-1, data, len); // write over trailing 0
}
/*
--- a/console.c
+++ b/console.c
@@ -145,7 +145,7 @@
if (con_linewidth < numchars)
numchars = con_linewidth;
- memcpy(tbuf, con_text, CON_TEXTSIZE);
+ memmove(tbuf, con_text, CON_TEXTSIZE);
memset(con_text, ' ', CON_TEXTSIZE);
for (i=0 ; i<numlines ; i++)
--- a/draw.c
+++ b/draw.c
@@ -348,7 +348,7 @@
v = (vid.conheight - lines + y) * 200 / vid.conheight;
src = conback->pixels + v * 320;
if(vid.conwidth == 320)
- memcpy(dest, src, vid.conwidth*sizeof(pixel_t));
+ memmove(dest, src, vid.conwidth*sizeof(pixel_t));
else{
f = 0;
fstep = 320 * 0x10000 / vid.conwidth;
@@ -394,7 +394,7 @@
}
}else{
for (i=0 ; i<prect->height ; i++){
- memcpy (pdest, psrc, prect->width*sizeof(pixel_t));
+ memmove (pdest, psrc, prect->width*sizeof(pixel_t));
psrc += rowbytes;
pdest += vid.width;
}
--- a/fs.c
+++ b/fs.c
@@ -709,7 +709,7 @@
}
r = 0;
loadedicts(bf, sv.pr);
- memcpy(svs.clients->spawn_parms, sp, sizeof sp);
+ memmove(svs.clients->spawn_parms, sp, sizeof sp);
exit:
return r;
}
--- a/menu.c
+++ b/menu.c
@@ -114,16 +114,16 @@
identityTable[j] = j;
dest = translationTable;
source = identityTable;
- memcpy (dest, source, 256);
+ memmove (dest, source, 256);
if (top < 128) // the artists made some backwards ranges. sigh.
- memcpy (dest + TOP_RANGE, source + top, 16);
+ memmove (dest + TOP_RANGE, source + top, 16);
else
for (j=0 ; j<16 ; j++)
dest[TOP_RANGE+j] = source[top+15-j];
if (bottom < 128)
- memcpy (dest + BOTTOM_RANGE, source + bottom, 16);
+ memmove (dest + BOTTOM_RANGE, source + bottom, 16);
else
for (j=0 ; j<16 ; j++)
dest[BOTTOM_RANGE+j] = source[bottom+15-j];
--- a/model_bsp.c
+++ b/model_bsp.c
@@ -368,7 +368,7 @@
}
if(mod->visdata == nil)
- memcpy(mod->visdata = Hunk_Alloc(sz), in, sz);
+ memmove(mod->visdata = Hunk_Alloc(sz), in, sz);
return 0;
}
@@ -378,7 +378,7 @@
if(sz == 0)
mod->entities = nil;
else
- memcpy(mod->entities = Hunk_Alloc(sz), in, sz);
+ memmove(mod->entities = Hunk_Alloc(sz), in, sz);
return 0;
}
--- a/model_bsp30.c
+++ b/model_bsp30.c
@@ -14,7 +14,7 @@
return 0;
}
- memcpy(mod->entities = Hunk_Alloc(sz), in, sz);
+ memmove(mod->entities = Hunk_Alloc(sz), in, sz);
if((s = strstr((char*)mod->entities, "\"wad\"")) == nil ||
(s = strchr(s+5, '"')) == nil ||
(e = strchr(s+1, '"')) == nil)
@@ -47,7 +47,7 @@
return 0;
}
- memcpy(mod->lightdata = Hunk_Alloc(sz), in, sz);
+ memmove(mod->lightdata = Hunk_Alloc(sz), in, sz);
return 0;
}
--- a/net_dgrm_plan9.c
+++ b/net_dgrm_plan9.c
@@ -32,7 +32,7 @@
hnputl(netbuf, NET_HEADERSIZE + n | f);
hnputl(netbuf+4, seq);
if(buf != nil)
- memcpy(netbuf+8, buf, n);
+ memmove(netbuf+8, buf, n);
return udpwrite(netbuf, NET_HEADERSIZE + n, a);
}
@@ -52,7 +52,7 @@
fatal("SendMessage: called with canSend == false\n");
#endif
- memcpy(s->sendMessage, data->data, data->cursize);
+ memmove(s->sendMessage, data->data, data->cursize);
s->sendMessageLength = data->cursize;
if(data->cursize <= MAX_DATAGRAM){
n = data->cursize;
@@ -231,7 +231,7 @@
sock->sendMessageLength -= MAX_DATAGRAM;
if (sock->sendMessageLength > 0)
{
- memcpy(sock->sendMessage, sock->sendMessage+MAX_DATAGRAM, sock->sendMessageLength);
+ memmove(sock->sendMessage, sock->sendMessage+MAX_DATAGRAM, sock->sendMessageLength);
sock->sendNext = true;
}
else
@@ -265,7 +265,7 @@
break;
}
- memcpy(sock->receiveMessage + sock->receiveMessageLength, netbuf+8, n);
+ memmove(sock->receiveMessage + sock->receiveMessageLength, netbuf+8, n);
sock->receiveMessageLength += n;
continue;
}
@@ -558,7 +558,7 @@
// everything is allocated, just fill in the details
sock->socket = newsock;
sock->landriver = net_landriverlevel;
- memcpy(&sock->addr, &clientaddr, sizeof clientaddr);
+ memmove(&sock->addr, &clientaddr, sizeof clientaddr);
strcpy(sock->address, UDP_AddrToString(&clientaddr));
// send him back the info about the server connection he has been allocated
@@ -616,7 +616,7 @@
// connect to the host
if (dfunc.Connect(&sendaddr) == -1)
goto ErrorReturn;
- memcpy(&readaddr, &sendaddr, sizeof readaddr);
+ memmove(&readaddr, &sendaddr, sizeof readaddr);
// send the connection request
Con_Printf("trying...\n"); SCR_UpdateScreen (false);
@@ -682,7 +682,7 @@
do{
if(getnewcon(&sendaddr) > 0){
close(readaddr.fd);
- memcpy(&readaddr, &sendaddr, sizeof readaddr);
+ memmove(&readaddr, &sendaddr, sizeof readaddr);
break;
}
sleep(1);
@@ -716,7 +716,7 @@
if (ret == CPACCEPT)
{
- memcpy(&sock->addr, &readaddr, sizeof readaddr);
+ memmove(&sock->addr, &readaddr, sizeof readaddr);
dfunc.SetSocketPort (&sock->addr, MSG_ReadLong());
}
else
--- a/net_loop.c
+++ b/net_loop.c
@@ -97,7 +97,7 @@
sock->receiveMessageLength -= length;
if (sock->receiveMessageLength)
- memcpy(sock->receiveMessage, &sock->receiveMessage[length], sock->receiveMessageLength);
+ memmove(sock->receiveMessage, &sock->receiveMessage[length], sock->receiveMessageLength);
if (sock->driverdata && ret == 1)
((qsocket_t *)sock->driverdata)->canSend = true;
@@ -132,7 +132,7 @@
buffer++;
// message
- memcpy(buffer, data->data, data->cursize);
+ memmove(buffer, data->data, data->cursize);
*bufferLength = IntAlign(*bufferLength + data->cursize + 4);
sock->canSend = false;
@@ -166,7 +166,7 @@
buffer++;
// message
- memcpy(buffer, data->data, data->cursize);
+ memmove(buffer, data->data, data->cursize);
*bufferLength = IntAlign(*bufferLength + data->cursize + 4);
return 1;
}
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -688,7 +688,7 @@
checkpvs = realloc(checkpvs, size);
checkpvs_size = size;
}
- memcpy (checkpvs, pvs, size);
+ memmove (checkpvs, pvs, size);
return i;
}
--- a/r_sprite.c
+++ b/r_sprite.c
@@ -67,7 +67,7 @@
// handle wraparound case
dists[nump] = dists[0];
- memcpy(instep, in, sizeof(vec5_t));
+ memmove(instep, in, sizeof(vec5_t));
// clip the winding
@@ -78,7 +78,7 @@
{
if (dists[i] >= 0)
{
- memcpy(outstep, instep, sizeof(vec5_t));
+ memmove(outstep, instep, sizeof(vec5_t));
outstep += sizeof (vec5_t) / sizeof (float);
outcount++;
}
--- a/stb_vorbis.c
+++ b/stb_vorbis.c
@@ -1301,7 +1301,7 @@
{
if (USE_MEMORY(z)) {
if (z->stream+n > z->stream_end) { z->eof = 1; return 0; }
- memcpy(data, z->stream, n);
+ memmove(data, z->stream, n);
z->stream += n;
return 1;
}
@@ -2974,7 +2974,7 @@
assert(f->alloc.alloc_buffer_length_in_bytes == f->temp_offset);
// re-enable coupled channels if necessary
- memcpy(really_zero_channel, zero_channel, sizeof(really_zero_channel[0]) * f->channels);
+ memmove(really_zero_channel, zero_channel, sizeof(really_zero_channel[0]) * f->channels);
for (i=0; i < map->coupling_steps; ++i)
if (!zero_channel[map->chan[i].magnitude] || !zero_channel[map->chan[i].angle]) {
zero_channel[map->chan[i].magnitude] = zero_channel[map->chan[i].angle] = false;
@@ -3450,7 +3450,7 @@
c->codeword_lengths = (u8int *) setup_malloc(f, c->entries);
if (c->codeword_lengths == nil) return error(f, VORBIS_outofmem);
- memcpy(c->codeword_lengths, lengths, c->entries);
+ memmove(c->codeword_lengths, lengths, c->entries);
setup_temp_free(f, lengths, c->entries); // note this is only safe if there have been no intervening temp mallocs!
lengths = c->codeword_lengths;
c->sparse = 0;
@@ -5122,7 +5122,7 @@
if (n+k >= num_samples) k = num_samples - n;
if (k) {
for (i=0; i < z; ++i)
- memcpy(buffer[i]+n, f->channel_buffers[i]+f->channel_buffer_start, sizeof(float)*k);
+ memmove(buffer[i]+n, f->channel_buffers[i]+f->channel_buffer_start, sizeof(float)*k);
for ( ; i < channels; ++i)
memset(buffer[i]+n, 0, sizeof(float) * k);
}
--- a/sv_main.c
+++ b/sv_main.c
@@ -316,7 +316,7 @@
netconnection = client->netconnection;
if(sv.loadgame)
- memcpy(spawn_parms, client->spawn_parms, sizeof spawn_parms);
+ memmove(spawn_parms, client->spawn_parms, sizeof spawn_parms);
memset(client, 0, sizeof *client);
client->netconnection = netconnection;
@@ -330,7 +330,7 @@
client->message.name = "client.message";
if(sv.loadgame)
- memcpy(client->spawn_parms, spawn_parms, sizeof spawn_parms);
+ memmove(client->spawn_parms, spawn_parms, sizeof spawn_parms);
else{
// call the progs to get default spawn parms for the new client
PR_ExecuteProgram(sv.pr, sv.pr->global_struct->SetNewParms);