Page MenuHomeFreeBSD

Fix index hardcoding, potential name collisions with reserved words, and fix uninitialized variable access
ClosedPublic

Authored by ngie on Jan 3 2016, 10:36 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, May 26, 11:19 PM
Unknown Object (File)
Mon, May 6, 5:59 AM
Unknown Object (File)
May 3 2024, 7:23 AM
Unknown Object (File)
May 3 2024, 7:23 AM
Unknown Object (File)
May 3 2024, 7:23 AM
Unknown Object (File)
May 3 2024, 7:23 AM
Unknown Object (File)
May 3 2024, 5:03 AM
Unknown Object (File)
Apr 26 2024, 8:53 PM
Subscribers

Details

Reviewers
oshogbo
Summary

Fix index hardcoding and potential name collisions with reserved words

  • Rename nitems variable to num_items to avoid overshadowing nitems(..) macro
  • Use nitems(..) instead of hardcoding indexes
  • Change i/index from int to unsigned int type for consistency with other variables and to fix -Wsign-compare warnings
  • Rename string to string_arr to make it clear that it's char**, not char*, and to also avoid potential issues with reserved keywords in languages (C/C++) or interfaces that might crop up in the future
  • Fix uninitialized variable access that was causing a large degree of grief on stable/10 when I was running the tests as noted in https://reviews.freebsd.org/D4767 .

MFC after: 5 days
Sponsored by: EMC / Isilon Storage Division

Test Plan
  • Built the change with both clang and gcc5 successfully on head.

% kyua test -k /usr/tests/lib/libnv/Kyuafile

Diff Detail

Event Timeline

ngie retitled this revision from to Fix index hardcoding and potential name collisions with reserved words.
ngie updated this object.
ngie edited the test plan for this revision. (Show Details)
ngie added a reviewer: oshogbo.
ngie added a subscriber: pjd.
lib/libnv/tests/nv_array_tests.cc
31 ↗(On Diff #11895)

I need to restore this. For some odd reason sys/dnv.h isn't getting size_t from sys/param.h...

Some extra comments.

lib/libnv/tests/nv_array_tests.cc
120–124

num_items == nitems(string_arr) ?

236–237

num_items == nitems(number) ?

ngie marked 2 inline comments as done.
ngie edited edge metadata.
  • Fix a few more hardcoded items by using nitems(..)
  • Re-add sys/types.h for size_t in sys/dnv.h (it isn't needed on head, but it's definitely needed on stable/10 for some odd reason :(..)

Remove some variables that are accessed incorrectly (they're not initialized)

This fixes the tests when run on stable/10

ngie retitled this revision from Fix index hardcoding and potential name collisions with reserved words to Fix index hardcoding, potential name collisions with reserved words, and fix uninitialized variable access.Jan 4 2016, 2:21 AM
ngie updated this object.
oshogbo edited edge metadata.

Possibly we could change those few lines but outside that please commit it ASAP ;)

lib/libnv/tests/nv_array_tests.cc
64

i < nitems(testbool) ?

67

, nitems(testbool));

74

, nitems(testbool));

145

i < nitems(string_arr) or num_items

This revision is now accepted and ready to land.Jan 4 2016, 2:34 AM
ngie marked 4 inline comments as done.

Committed as r293130, r293131, r293134, and r293135. Thank you for all the help Mariusz :)!!!