Page MenuHomePhabricator

minor refactor to use ranged_for, auto and const-ness
ClosedPublic

Authored by majcosta on Nov 20 2019, 19:08.

Details

Summary

as above

edit: also renamed a variable that used Hungarian notation

Test Plan

created a minor cpp unit test which replicated the desired behavior in the code. that being insufficient, as soon as my node syncs I'll prune it, set a breakpoint and verify correct behavior

edit: To check for correct behavior, wrote a test that creates empty blk000xx.dat and rev000xx.dat files from 0 to 28, with contiguous and non-contiguous segments, and runs the CleanupBlockRevFiles() function. then, this test will be run with clang's address, memory and undefined sanitizers, in turn.

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Owners added a reviewer: Restricted Owners Package.Nov 20 2019, 19:08
deadalnix requested changes to this revision.Nov 20 2019, 21:17
deadalnix added inline comments.
src/init.cpp
1100 ↗(On Diff #14263)

This is going to create copies.

This revision now requires changes to proceed.Nov 20 2019, 21:17
src/init.cpp
1100 ↗(On Diff #14263)

not 100% sure I understand. you mean copies of std::string? should fileName be a reference instead?

changed fileName from value to reference semantics

deadalnix requested changes to this revision.Nov 21 2019, 15:45

I fell like you are a bit overdoing it with auto here. I'm not against auto in general, but C++ is a bit trigger happy with copies and implicit conversions.

You also want to run this through UBSAN to make sure you are not keeping a reference to a temporary as part of your test plan.

src/init.cpp
1100 ↗(On Diff #14298)

Use const auto rather than auto const.

This revision now requires changes to proceed.Nov 21 2019, 15:45
majcosta edited the test plan for this revision. (Show Details)
majcosta edited the test plan for this revision. (Show Details)

I have run the test using const auto &fileName and it did set off the -fsanitize=address giving me a stack-use-after-scope error, so I went back to by-value semantics. address,undefined and memory sanitizer reported no problems after that (except for one use-of-uninitialized-value on Boost)

about all that auto, I compiled my test in a local compiler explorer instance, side by side, using auto in one snippet and fully spelled out types on everything in the other, and the resulting assembly was exactly the same for both g++ and clang, would that be ok then?

This revision is now accepted and ready to land.Nov 22 2019, 12:27