Skip to content

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'; because fgets() NULL terminates the buffer already.
  • Changed memset(buffer, 0, strlen(buffer)); and used sizeof(buffer) since buffer is filled using the fgets() function which will not stop reading if it encounters \0. This means it might be possible that the call to memset does not zero-out all the data that fgets read. 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 to memset.

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

Merge request reports

Loading