Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

int main()
{
char name[64];
char name[128];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increasing the buffer size from 64 to 128 characters is a good approach to handle longer inputs and prevent buffer overflow issues.


printf("Enter your name:\n");
fgets(name, sizeof(name) + 32, stdin);
fgets(name, sizeof(name), stdin);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correcting the fgets usage to sizeof(name) instead of sizeof(name) + 32 is crucial for preventing buffer overflows. Good fix!


// Remove the trailing newline character if present
name[strcspn(name, "\n")] = '\0';
Expand Down