Created
October 5, 2012 23:25
-
-
Save orangejulius/3843041 to your computer and use it in GitHub Desktop.
Simple memcpy implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
void* my_memcpy(void* destination, void* source, size_t num) | |
{ | |
int i; | |
char* d = destination; | |
char* s = source; | |
for (i = 0; i < num; i++) { | |
d[i] = s[i]; | |
} | |
return destination; | |
} | |
int main() | |
{ | |
char str1[]="Humble Bundle is awesome."; | |
char str2[26]; | |
char str3[10]; | |
void* r1 = my_memcpy(str2, str1, 5); | |
printf("str2 is %s, r1 is %p\n", str2, r1); | |
void* r2 = my_memcpy(str2, str1, 26); | |
printf("str2 is %s, r2 is %p\n", str2, r2); | |
//This will cause an overflow | |
//void* r3 = my_memcpy(str3, str1, 26); | |
//printf("str3 is %s, r3 is %p\n", str3, r3); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
signature should be
void* my_memcpy(void* destination, const void* source, size_t num)