An array with 7 elements was setup for checking argument parsing, but was passed to ParseParamaeters with argc=5, meaning the interpretation of the last two arguments was never actually checked.
[tests] util_tests.cpp: actually check ignored args #11997
pull ajtowns wants to merge 1 commits into bitcoin:master from ajtowns:parseparam-fix changing 1 files +1 −1-
ajtowns commented at 2:19 PM on December 23, 2017: member
- fanquake added the label Tests on Dec 23, 2017
- ajtowns force-pushed on Dec 23, 2017
-
in src/test/util_tests.cpp:124 in 4e196a98a4 outdated
120 | @@ -121,7 +121,8 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters) 121 | testArgs.ParseParameters(1, (char**)argv_test); 122 | BOOST_CHECK(testArgs.GetMapArgs().empty() && testArgs.GetMapMultiArgs().empty()); 123 | 124 | - testArgs.ParseParameters(5, (char**)argv_test); 125 | + static_assert(7 * sizeof(argv_test[0]) == sizeof(argv_test), "argv_test length has changed");
promag commented at 2:38 AM on January 2, 2018:IMO remove this assert.
ajtowns commented at 12:16 PM on January 3, 2018:The assert doesn't have any runtime cost, and documents/enforces the change as well as helping avoid the same mistake happening again, so seems better to have it to me?
An alternative approach is using templates to directly determine the size of the array:
template<size_t N> inline void ParseParameters(int argc, const char* (&argv)[N]) { assert(argc >= 0 && (size_t) argc < N); ArgsManager::ParseParameters(argc, (char**) argv); } template<size_t N> inline void ParseParameters(const char* (&argv)[N]) { ArgsManager::ParseParameters(N, (char**) argv); } ... testArgs.ParseParameters(1, argv_test); // to test only some args testArgs.ParseParameters(argv_test); // to test all args
MarcoFalke commented at 1:06 PM on January 3, 2018:Since passing an
argcthat does not specify the size ofargvis only ever used in tests, you could passargv_test.size()instead of7by switching toconst std::array<const char*, 7> argv_test = {... braced-init-list ...}
MarcoFalke commented at 1:14 PM on January 3, 2018:That makes it robust to future changes, but not robust to future changes that remove the trailing or the two trailing args. Imo such buggy changes must be covered by code review. Not excessive documentation. Note that we are talking about a function that spans about 20 lines... If code review does not work on that scale we have far worse issues.
ajtowns commented at 2:15 PM on January 3, 2018:Removed
promag commented at 2:39 AM on January 2, 2018: memberutACK 4e196a9.
MarcoFalke commented at 1:15 PM on January 3, 2018: memberConcept ACK, but agree with @promag
c99a3c32c8[tests] util_tests.cpp: actually check ignored args
An array with 7 elements was setup for checking argument parsing, but was passed to ParseParamaeters with argc=5, meaning the interpretation of the last two arguments was never actually checked.
ajtowns force-pushed on Jan 3, 2018MarcoFalke commented at 2:09 PM on January 4, 2018: member-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 utACK c99a3c32c830384a9959a468a13441fcd2e48a72 -----BEGIN PGP SIGNATURE----- iQIcBAEBCgAGBQJaTjV7AAoJENLqSFDnUoslYJUP+wRtblQkTEa0UlmhOiDk4KFa BPiYWVsYCIfS2Mt7OtQq0RlxcGnNydneulsVQHzOhzTMo0DQdvKS32W5sUzhCjUa JBc3McQ1kprl0NoiHoD3VuR2YbSdBPs8iwue14oD1ilNjGO3P6SlJdiv6Cg5svN0 FdpTEsJFkaZqIbceG4kfOlHnxqMhfUuaXoXCcN4KEPVG+FqUCE5fyxZAGlGEqwjW WqkmcPK2caRXovv9DKTKHjPNp9KjGIR9zkKTd+upLMkormW9A5yCD9fyJCwjTBD2 eHc34VjjiRS043V3Q8bZpxMVGxZoPCv5ZZPol1whQY0fmbX3mTiDelp+IlCHX50L LQ4x/zhQ18+EjP4tbYQYyT7TrHljt8v6ai14+zqjTXyfZDN2ba75SlfTzO6qxi9Z Iw6eEIDK5HxnMmtCXLxNNV9eIjiaH9lnNzt0S177MRacDn2KClZcsDOEodXCqy99 OXvL4jYYZY/d86kLZskWfpYYNRoFf67s6ybYLj6coS5hMeRFBDJrmng0AcMohib6 +ixWmA8d4kXjZGgepRMkjMQtLaxvc0Sa0lAzAJ8io3jkB+0wbL9aap7Qb/hrybcu /h7psyPdUyRTbOxuf3+7ke/X9xmY51vwshxbq3aGOPSidMbnPX2Tjo4szjAw7je2 oabzFOrUMgtIzDt4H+57 =kwru -----END PGP SIGNATURE-----MarcoFalke merged this on Jan 4, 2018MarcoFalke closed this on Jan 4, 2018MarcoFalke referenced this in commit ddff3447f2 on Jan 4, 2018jasonbcox referenced this in commit b8cbd5598f on Jul 25, 2019PastaPastaPasta referenced this in commit 78727faf57 on Mar 23, 2020PastaPastaPasta referenced this in commit 93a493b266 on Mar 28, 2020PastaPastaPasta referenced this in commit 34b4ef45e9 on Mar 29, 2020PastaPastaPasta referenced this in commit aa3f8e16a8 on Mar 31, 2020UdjinM6 referenced this in commit 500d6f1fb8 on Mar 31, 2020PastaPastaPasta referenced this in commit adec6e262e on Apr 1, 2020ckti referenced this in commit b82b572fb0 on Mar 28, 2021gades referenced this in commit 11f48b7b17 on Jun 30, 2021DrahtBot locked this on Sep 8, 2021ContributorsLabels
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-26 09:15 UTC
More mirrored repositories can be found on mirror.b10c.me