diff options
-rw-r--r-- | include/lib/mem.h | 3 | ||||
-rw-r--r-- | src/lib/mem.c | 12 |
2 files changed, 9 insertions, 6 deletions
diff --git a/include/lib/mem.h b/include/lib/mem.h index 04056f7..646a170 100644 --- a/include/lib/mem.h +++ b/include/lib/mem.h @@ -15,7 +15,8 @@ struct MemTab { struct RotBuffer { void* base; unsigned int size; - unsigned int offset; + unsigned int roffset; + unsigned int woffset; }; void memset(unsigned char* dest, unsigned char value, unsigned int n); diff --git a/src/lib/mem.c b/src/lib/mem.c index dc915e6..e51ec32 100644 --- a/src/lib/mem.c +++ b/src/lib/mem.c @@ -5,13 +5,15 @@ void memcpyrot(unsigned char* src, struct RotBuffer* rb, unsigned int n) { if (n > rb->size) return; - unsigned char* addr = rb->base + rb->offset; + unsigned char* base = rb->base; + unsigned int offset = rb->woffset; for (unsigned int i = 0; i < n; i++) { - if (addr >= (unsigned char*)(rb->base + rb->size)) - addr = rb->base; - *addr = src[i]; - addr++; + if (offset >= rb->size) + offset = 0; + base[offset] = src[i]; + offset++; } + rb->woffset = offset; } void memshow32(unsigned long* addr, unsigned int n) |