Created
June 3, 2015 06:09
-
-
Save danish-rehman/0cb490d52cb37fdf37e3 to your computer and use it in GitHub Desktop.
strncat bound check
This file contains hidden or 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" | |
#define MAXBUF 10 | |
int main(int argc, char **argv) | |
{ | |
char buf[MAXBUF]; // enough room for 9 characters and one '\0' | |
strcpy(buf,"hello "); // use 6 characters | |
strncat(buf, "world!\n", 3);// Strncat() wants the maximum number | |
// of characters it can copy (not counting the | |
// terminating null). In this case, there are 3 | |
// free characters left in buf. | |
// The length passed to strncat() would | |
// typically be equivalent to | |
// MAXBUF-1-strlen(buf). | |
printf("%s\n", buf) | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment