ptrdiff_t is a more strictly correct type, and gets rid of compiler warnings.
Libraries: Use correct type ; avoid compiler warnings. #12351
pull murrayn wants to merge 1 commits into bitcoin:master from murrayn:ptrdiff_t changing 1 files +3 −3-
murrayn commented at 10:58 AM on February 5, 2018: contributor
-
Use ptrdiff_t type to more precisely indicate usage and avoid compiler warnings. a25cb0f313
- fanquake added the label Refactoring on Feb 5, 2018
-
MarcoFalke commented at 12:28 PM on February 5, 2018: member
Duplicate of #12286
- MarcoFalke marked this as duplicate on Feb 5, 2018
-
murrayn commented at 12:01 AM on February 6, 2018: contributor
I wasn't aware of another PR dealing with the compiler warnings. However, the solutions are not duplicates. I think changing the type to ptrdiff_t as I do here is more correct than the casting solution. The cast solution is just masking the problem.
- murrayn renamed this:
Libraries: Use type more precisely indicating usage and avoid compilers warnings.
Libraries: Use correct type ; avoid compiler warnings.
on Feb 7, 2018 -
devrandom commented at 4:42 PM on February 8, 2018: none
-
laanwj commented at 7:44 PM on February 8, 2018: member
-
laanwj commented at 7:46 PM on February 8, 2018: member
One question though, for @sipsorcery maybe - is
ptrdiff_tsupported with MSVC? We're not using it anywhere and I remember problems withssize_t. -
practicalswift commented at 9:08 PM on February 8, 2018: contributor
utACK a25cb0f313315bd987834aa5f500b5682a9c3cd5
-
Empact commented at 9:22 PM on February 8, 2018: member
@laanwj Untested but they list it as of VS2008: https://msdn.microsoft.com/en-us/library/323b6b3k(v=vs.90).aspx
-
sipsorcery commented at 9:51 PM on February 8, 2018: member
@laanwj ptrdiff_t is defined in vcruntime.h with MSVC. This change builds with Visual Studio.
-
laanwj commented at 10:37 AM on February 12, 2018: member
@sipsorcery Thanks for checking!
-
in src/key.cpp:69 in a25cb0f313
65 | @@ -66,7 +66,7 @@ static int ec_privkey_import_der(const secp256k1_context* ctx, unsigned char *ou 66 | if (end - privkey < 2 || privkey[0] != 0x04u) { 67 | return 0; 68 | } 69 | - size_t oslen = privkey[1]; 70 | + ptrdiff_t oslen = privkey[1];
laanwj commented at 10:40 AM on February 12, 2018:Checked that neither of the values whose type changed can ever be negative, or overflow, given that the range of privkey[x] is 0..255.
laanwj merged this on Feb 12, 2018laanwj closed this on Feb 12, 2018laanwj referenced this in commit c8b54b2044 on Feb 12, 2018PastaPastaPasta referenced this in commit 3d5ac7e5db on Jun 10, 2020PastaPastaPasta referenced this in commit ebcdf8c28c on Jun 12, 2020PastaPastaPasta referenced this in commit 69e76bd9cd on Jun 13, 2020PastaPastaPasta referenced this in commit 1be7b4d1d9 on Jun 14, 2020PastaPastaPasta referenced this in commit 7dc8c4e687 on Jun 14, 2020gades referenced this in commit b22cb62c00 on Jun 24, 2021DrahtBot locked this on Sep 8, 2021Labels
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-21 18:15 UTC
More mirrored repositories can be found on mirror.b10c.me