- Switched a few hardcoded constants to sizeof()
- Broke conditional chains into separate lines with leading conditionals
[trivial] Switched constants to sizeof() #8321
pull tjps wants to merge 1 commits into bitcoin:master from tjps:tjps_cleanups changing 2 files +23 −16-
tjps commented at 11:58 PM on July 8, 2016: contributor
-
MarcoFalke commented at 9:48 AM on July 10, 2016: member
Broke conditional chains into separate lines with leading conditionals
Our code style is to use the exact opposite... I appreciate your desire to clean up the code base, but I think it touches a lot of lines and thus invalidates any patches of other pulls or patches that developers have in their local tree. Also, I think the cost of review and repository churn is not worth the benefits of this particular pull request.
-
laanwj commented at 10:04 AM on July 11, 2016: member
Agree with @MarcoFalke. Thanks for trying to help, but in general these kinds of pulls which just massage around spaces and newlines aren't well-received. They break other people's patches for no good reason: the difficulty in reading bitcoin core code is not in how the whitespace is organized.
-
tjps commented at 7:36 PM on July 12, 2016: contributor
Apologies for missing the section of the codestyle guidelines where it specified trailing conditionals and/or preference for longer lines, I still can't find that part.
So the hardcoded constant to sizeof() conversions are also not seen as worthwhile? It seems that memcpy() with a hardcoded size is asking for trouble down the line.
-
MarcoFalke commented at 8:03 PM on July 12, 2016: member
I still can't find that part.
It is not possible to list all code style preferences. You can use the clang-format-diff.py in the contrib folder if you contribute new code and want to be "on the safe side". Other than that, the code style is usually just defined by the way the local code is written.
- MarcoFalke added the label Refactoring on Jul 12, 2016
-
MarcoFalke commented at 2:07 PM on July 16, 2016: member
So the hardcoded constant to sizeof() conversions are also not seen as worthwhile? It seems that memcpy() with a hardcoded size is asking for trouble down the line.
I think it is not required to use sizeof() when anything other than the hardcoded value would not make sense.
-
tjps commented at 2:55 AM on July 17, 2016: contributor
I understand that people are particular about code formatting, and I can even understand the trepidation about branches interfering with each other, despite diff resolution/merging being one of git's strengths.
But never in any project I've contributed to before have I seen someone claim that
memcpy(A, B, <constant>)
is better, preferred, or even equivalent to
memcpy(A, B, sizeof(A))
My hope with a small cleanup branch was to get a feel for the process of submitting to this project before taking on more substantial TODOs, but I get the feeling that is not welcome here.
I'll discard this PR. Thanks for your time.
-
MarcoFalke commented at 8:22 AM on July 17, 2016: member
@tjps Generally you are correct but in this case it is always 32 bytes just by definition. Going to hide this information behind
sizeof()would make this less clear. @tjps Don't get me wrong here. Your desire to help is really appreciated but we must keep code-style-only pulls to a minimum as there was nasty bugs introduced in the past by accident.If you want to get a feel for the process of submitting to this project, we have prepared a list of "easy to do" issues here: https://github.com/bitcoin/bitcoin/labels/Easy%20to%20implement
Note that not all issues are tracked. If you want to help with qa and tests for example, you can ping me to get me compile a list of outstanding improvements.
Also, you can pick a random pull and compile it locally to do see if it does what it is supposed to do. Then report your findings in the pull. Usually you will find a ton of trivial stuff to improve by this. For example: #8336. (Just keep in mind to leave style-only-fixes to a minimum for now)
-
sipa commented at 10:54 AM on July 17, 2016: member
About the 32 -> sizeof(vch) change... I agree that sizeof(vch) is cleaner, but if a change would be made that changes vch's size, things would break in more subtle ways (because the serialization of keys would differ).
One possibility is doing the 32 -> sizeof(vch), but also adding an asset/static_assert that sizeof(vch) == 32, with a comment explaining that this can't just be changed. That way you get both properties.
-
tjps commented at 5:16 AM on July 18, 2016: contributor
OK, how about this as a compromise: I backed out all of the other changes except for the sizeof(), and breaking the conditional chains to one-per-line, which I still assert is a readability win.
I also added a static_assert, which I think is a step better beyond switching to sizeof() - thanks @sipa.
Does this seem reasonable?
-
jtimon commented at 3:49 PM on July 18, 2016: contributor
It sounds reasonable to me. Concept ack on the sizeof changes only.
-
MarcoFalke commented at 4:02 PM on July 18, 2016: member
@tjps Can you try to squash the commits
git reset c96c1a9~ git commit --verbose -a -
[trivial] Switched constants to sizeof() fbc60703a5
-
tjps commented at 2:44 AM on July 19, 2016: contributor
@MarcoFalke of course, my mistake. Was late at night.
- tjps renamed this:
Trivial: minor code cleanups for readability
[trivial] Switched constants to sizeof()
on Jul 21, 2016 -
tjps commented at 7:54 PM on July 25, 2016: contributor
Hi all, checking in at the one week mark. Is there anything else I can do to get this merged? Hoping to move on to the easy-to-implement list next.
-
sipa commented at 7:58 PM on July 25, 2016: member
utACK
-
laanwj commented at 11:37 AM on July 28, 2016: member
The changes here are much easier to review with
git diff --word-diffthan the github output. utACK fbc6070 -
in src/pubkey.h:None in fbc60703a5
202 | @@ -203,8 +203,11 @@ struct CExtPubKey { 203 | 204 | friend bool operator==(const CExtPubKey &a, const CExtPubKey &b) 205 | { 206 | - return a.nDepth == b.nDepth && memcmp(&a.vchFingerprint[0], &b.vchFingerprint[0], 4) == 0 && a.nChild == b.nChild && 207 | - a.chaincode == b.chaincode && a.pubkey == b.pubkey; 208 | + return a.nDepth == b.nDepth && 209 | + memcmp(&a.vchFingerprint[0], &b.vchFingerprint[0], sizeof(vchFingerprint)) == 0 &&
laanwj commented at 11:40 AM on July 28, 2016:Note: This only works because
vchFingerprintis not, as the variable name implies, a vector of char, but instead an array char[4].laanwj merged this on Jul 28, 2016laanwj closed this on Jul 28, 2016laanwj referenced this in commit 133c727cc4 on Jul 28, 2016tjps deleted the branch on May 18, 2017codablock referenced this in commit 26e90781e5 on Sep 19, 2017codablock referenced this in commit 948a822c81 on Dec 29, 2017codablock referenced this in commit b673b7bf65 on Jan 8, 2018andvgal referenced this in commit 0fcd4ac845 on Jan 6, 2019zkbot referenced this in commit 5ef5d8d268 on Jul 31, 2020zkbot referenced this in commit 7d94064616 on Sep 29, 2020DrahtBot 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-22 06:15 UTC
More mirrored repositories can be found on mirror.b10c.me