Page MenuHomeFreeBSD

libc: add test for strnlen()
ClosedPublic

Authored by strajabot on Aug 12 2024, 10:21 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Dec 29, 1:50 AM
Unknown Object (File)
Nov 23 2024, 10:44 AM
Unknown Object (File)
Nov 22 2024, 8:42 AM
Unknown Object (File)
Oct 17 2024, 7:25 PM
Unknown Object (File)
Oct 15 2024, 11:42 AM
Unknown Object (File)
Oct 14 2024, 2:56 PM
Unknown Object (File)
Sep 30 2024, 6:12 PM
Unknown Object (File)
Sep 21 2024, 10:57 PM
Subscribers

Details

Summary

Tests for strnlen, checks alignments from up to 16 and buffer sizes up to 64, also checks that passing SIZE_MAX as maxlen, because it can cause a wraparound error if strnlen is incorrect.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This test looks reasonable.

It might make sense to split SIZE_MAX tests into a separate main test case as it tests a special case of the function.

lib/libc/tests/string/strnlen_test.c
31

You should be able to do the memset only once outside of the loop. Note that initialising with ... = { '/' } only sets the first element of the buffer to '/', the others are set to zero. So memset is indeed needed.

33

maxlen should be of type size_t. Use %zu to print a variable of type size_t.

96–97
105–106

same change here

  • separate strnlen_alignments into two tests
This revision is now accepted and ready to land.Oct 14 2024, 7:06 PM
kib added inline comments.
lib/libc/tests/string/strnlen_test.c
26

Extra blank line

29
32
35
41
43

Indent is wrong

51
53

Same style issues below

87

Extra blank line

This revision was automatically updated to reflect the committed changes.