Refactor: Remove redundant line and change strlen(buffer) to sizeof(buffer) in examples/authentication.c
I made two changes to examples/authentication.c:
- Removed the line
buffer[sizeof(buffer) - 1] = '\0';becausefgets()NULL terminates the buffer already. - Changed
memset(buffer, 0, strlen(buffer));and usedsizeof(buffer)since buffer is filled using thefgets()function which will not stop reading if it encounters\0. This means it might be possible that the call tomemsetdoes not zero-out all the data thatfgetsread. While we know the user of this application will not likely provide such input, it is better to change the code to be on the safe side. This is also consistent with the rest of the calls tomemset.
Checklist
-
Commits have Signed-off-by:with name/author being identical to the commit author -
Code modified for feature -
Test suite updated with functionality tests -
Test suite updated with negative tests -
Documentation updated
Reviewer's checklist:
-
Any issues marked for closing are addressed -
There is a test suite reasonably covering new functionality or modifications -
Function naming, parameters, return values, types, etc., are consistent and according to CONTRIBUTING.md -
This feature/change has adequate documentation added -
No obvious mistakes in the code