shithub: gefs

Download patch

ref: 98d491b0e50f2dda669d5b8acdf4c0bad87590f9
parent: 0568aee47bbfe78e7ab608fda0b667e4508ada0c
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Nov 7 22:11:55 EST 2023

all: memcpy->memmove when sane

it shouldn't matter for perf, and it prevents simple
mistakes.

--- a/fs.c
+++ b/fs.c
@@ -1253,6 +1253,7 @@
 				(*ao)->dent = de;
 				truncate = 1;
 			}
+			de->length = d.length;
 			n.length = d.length;
 			op |= Owsize;
 			PACK64(p, n.length);
--- a/pack.c
+++ b/pack.c
@@ -124,10 +124,10 @@
 		*err = 1;
 		return p;
 	}
-	PACK16(p+0, n);
-	memcpy(p+2, s, n);
-	p[2+n] = 0;
-	return p+3+n;
+	PACK16(p, n);		p += 2;
+	memmove(p, s, n);	p += n;
+	*p = 0;			p += 1;
+	return p;
 }
 		
 int
--- a/tree.c
+++ b/tree.c
@@ -48,7 +48,7 @@
 cpkey(Key *dst, Key *src, char *buf, int nbuf)
 {
 	assert(src->nk <= nbuf);
-	memcpy(buf, src->k, src->nk);
+	memmove(buf, src->k, src->nk);
 	dst->k = buf;
 	dst->nk = src->nk;
 }
@@ -57,8 +57,8 @@
 cpkvp(Kvp *dst, Kvp *src, char *buf, int nbuf)
 {
 	assert(src->nk+src->nv <= nbuf);
-	memcpy(buf, src->k, src->nk);
-	memcpy(buf+ src->nk, src->v, src->nv);
+	memmove(buf, src->k, src->nk);
+	memmove(buf+ src->nk, src->v, src->nv);
 	dst->k = buf;
 	dst->nk = src->nk;
 	dst->v = buf+src->nk;
@@ -136,9 +136,9 @@
 
 	p = b->data + off;
 	PACK16(p, kv->nk);		p += 2;
-	memcpy(p, kv->k, kv->nk);	p += kv->nk;
+	memmove(p, kv->k, kv->nk);	p += kv->nk;
 	PACK16(p, kv->nv);		p += 2;
-	memcpy(p, kv->v, kv->nv);
+	memmove(p, kv->v, kv->nv);
 
 	b->nval++;
 }
@@ -172,11 +172,11 @@
 	PACK16(p, o);
 
 	p = b->data + Pivspc + o;
-	*p = m->op;		p += 1;
-	PACK16(p, m->nk);	p += 2;
-	memcpy(p, m->k, m->nk);	p += m->nk;
-	PACK16(p, m->nv);	p += 2;
-	memcpy(p, m->v, m->nv);
+	*p = m->op;			p += 1;
+	PACK16(p, m->nk);		p += 2;
+	memmove(p, m->k, m->nk);	p += m->nk;
+	PACK16(p, m->nv);		p += 2;
+	memmove(p, m->v, m->nv);
 
 	b->nbuf++;
 }
@@ -484,6 +484,7 @@
 	spc = Leafspc - blkfill(b);
 	if((n = newblk(t, b->type)) == nil)
 		return -1;
+	assert(i >= 0 && j >= 0);
 	while(i < b->nval){
 		ok = 1;
 		getval(p->b, i, &v);
@@ -1403,7 +1404,7 @@
 	s->offset = 0;
 	s->pfx.k = s->pfxbuf;
 	s->pfx.nk = npfx;
-	memcpy(s->pfxbuf, pfx, npfx);
+	memmove(s->pfxbuf, pfx, npfx);
 
 	s->kv.v = s->kvbuf+npfx;
 	s->kv.nv = 0;