On the second thought memmove was correct

This commit is contained in:
bumbread 2022-08-10 13:58:13 +11:00
parent f9fa35febe
commit 0abfd8cf3d
2 changed files with 13 additions and 1 deletions

View File

@ -12,7 +12,6 @@ void *memcpy(void *restrict s1, const void *restrict s2, size_t n) {
void *memmove(void *s1, const void *s2, size_t n) { void *memmove(void *s1, const void *s2, size_t n) {
u8* c1 = s1; u8* c1 = s1;
const u8* c2 = s2; const u8* c2 = s2;
// Note(bumbread): shouldn't this be backwards?
if (c1 != c2) { if (c1 != c2) {
if (c1 < c2) { if (c1 < c2) {
// reverse copy // reverse copy

13
test/stuff.c Normal file
View File

@ -0,0 +1,13 @@
#include <string.h>
#include <stdio.h>
int main() {
char arr[] = "Bruh\0\0\0";
printf("Before memmove: %s\n", &arr[0]);
memmove(arr+3, arr, 4);
printf("After memmove: %s\n", &arr[0]);
return 0;
}