07-26-2023, 07:08 AM
Writing more data into an array than it can hold can cause memory corruption and security vulnerabilities.
// Incorrect
char name[5];
strcpy(name, "John Doe"); // Buffer overflow
// Correct
char name[50];
strcpy(name, "John Doe");
// Incorrect
char name[5];
strcpy(name, "John Doe"); // Buffer overflow
// Correct
char name[50];
strcpy(name, "John Doe");