No description provided.
Refactor: simpler read #11221
pull gnuser wants to merge 1 commits into bitcoin:master from gnuser:refactor-streams changing 1 files +5 −7-
gnuser commented at 5:46 AM on September 3, 2017: contributor
-
Refactor: make the read function simpler 9db9d6215f
-
in src/streams.h:351 in 9db9d6215f
344 | @@ -345,18 +345,16 @@ class CDataStream 345 | 346 | // Read from the beginning of the buffer 347 | unsigned int nReadPosNext = nReadPos + nSize; 348 | - if (nReadPosNext >= vch.size()) 349 | + if (nReadPosNext > vch.size()) { 350 | + throw std::ios_base::failure("CDataStream::read(): end of data"); 351 | + } 352 | + memcpy(pch, &vch[nReadPos], nSize);
sipa commented at 6:44 AM on September 3, 2017:This is not correct. When
vchis empty, andnReadPosandnSizeare 0, this will invokeoperator[]on vch, which is not valid.
meshcollider commented at 7:34 AM on September 3, 2017:Note that that's a bug with the original code though, not with the refactor
laanwj commented at 5:42 PM on September 6, 2017:probably better to use
vch.data() + nNreadPos? (but yes, this is not a bug introduced in this PR)
sipa commented at 11:27 PM on October 12, 2017:Agree, there is no bug here. It would still be clearer using
vch.data() + nReadPosthough.dcousens approvedlaanwj added the label Refactoring on Sep 5, 2017promag commented at 4:24 PM on October 8, 2017: memberutACK 9db9d62.
Nit, commit message could mention
CDataStream::readinsteadreadonly.in src/streams.h:352 in 9db9d6215f
344 | @@ -345,18 +345,16 @@ class CDataStream 345 | 346 | // Read from the beginning of the buffer 347 | unsigned int nReadPosNext = nReadPos + nSize; 348 | - if (nReadPosNext >= vch.size()) 349 | + if (nReadPosNext > vch.size()) { 350 | + throw std::ios_base::failure("CDataStream::read(): end of data"); 351 | + } 352 | + memcpy(pch, &vch[nReadPos], nSize); 353 | + if (nReadPosNext == vch.size())
promag commented at 4:24 PM on October 8, 2017:Nit,
{on this line.laanwj merged this on Nov 9, 2017laanwj closed this on Nov 9, 2017laanwj referenced this in commit 0dec4cc300 on Nov 9, 2017PastaPastaPasta referenced this in commit 0f978bab3b on Jan 31, 2020PastaPastaPasta referenced this in commit fe38d4f5ee on Jan 31, 2020PastaPastaPasta referenced this in commit e2137607bf on Feb 4, 2020PastaPastaPasta referenced this in commit 2a018f8807 on Feb 9, 2020random-zebra referenced this in commit 8e7fa721af on Sep 27, 2020ckti referenced this in commit 31e45c0ace on Mar 28, 2021gades referenced this in commit a3194e3717 on Jun 30, 2021DrahtBot locked this on Sep 8, 2021
github-metadata-mirror
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
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
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me
More mirrored repositories can be found on mirror.b10c.me