So I was told if you useyou could prevent buffer overflow. However on compiling a test program, it returned BUFSIZE to be have 513 bytes max. Doesn't that mean if you go over 514 then you can have a buffer overflow.Code:char whatever[BUFSIZE +1]
Or does it make a difference if you useorCode:scanf()to get the user inputs.Code:gets()
Here is my code to determine BUFSIZCode:/* scanfTEST.c */ #include <stdio.h> #include <ctype.h> #define PRAISE "My that is a nice name" int main (void) { char name[BUFSIZ+1]; int size, nameLEN; printf("What is your name?\n"); scanf(" %s", name); /* ignores leading whitespace but not the following whitespace */ size = sizeof (name); nameLEN = strlen(name); printf("Hello, %s. %s\n", name, PRAISE); printf("Your name can hold max %d bytes. But its is now of %d charaters\n", size, nameLEN); system("pause"); return (0); }



LinkBack URL
About LinkBacks


