This pull request addresses the segmentation fault issue that occurs when a user inputs a name longer than 80 characters. The issue was caused by a buffer overflow due to the use of scanf without bounds checking. The following changes have been made to resolve the issue:
Replaced scanf with fgets to handle user input safely and prevent buffer overflow.
Removed the trailing newline character from the input string using strcspn.
Changes Made
Updated main.c:
Replaced scanf with fgets to limit the input length to the size of the buffer.
Added code to remove the trailing newline character from the input string.
Testing
The changes have been tested locally by running the program and inputting a name longer than 80 characters. The program no longer crashes and handles the input correctly.
Issue Reference
This pull request fixes the following issue:
Issue #1: Segmentation fault when name is longer than 80 characters
Additional Information
Please review the changes and let me know if any further modifications are required. Thank you!
Pull Request: Fix Segmentation Fault Issue
Description
This pull request addresses the segmentation fault issue that occurs when a user inputs a name longer than 80 characters. The issue was caused by a buffer overflow due to the use of
scanf
without bounds checking. The following changes have been made to resolve the issue:scanf
withfgets
to handle user input safely and prevent buffer overflow.strcspn
.Changes Made
main.c
:scanf
withfgets
to limit the input length to the size of the buffer.Testing
The changes have been tested locally by running the program and inputting a name longer than 80 characters. The program no longer crashes and handles the input correctly.
Issue Reference
This pull request fixes the following issue:
Additional Information
Please review the changes and let me know if any further modifications are required. Thank you!