I am currently jumping into my first full C ++ project and am having problems with Ncurses.
getstr () requires a char array, but it is not possible to prevent buffer overflows. Let's pretend to use this input to get a name. Then my code will be as follows:
int main(){
char* nameTemp = new char[160];
initscr();
getstr(nameTemp);
endwin();
delete nameTemp;
return 0;
}
But what happens if the user decides to use more than 160 characters for his name? I get an error and the program is not working. Is there a way to fix this fatal flaw in the program besides creating huge char arrays? Thank.
Note. I am using Ubuntu 12.04 with g ++
source
share