Skip to content

Commit

Permalink
Resize vectror size
Browse files Browse the repository at this point in the history
Fix GCC 11 warnings:
reading 1 or more bytes from a region of size 0 [-Wstringop-overread]

Fix GCC 12 warnings:
offset 1 is out of the bounds [0, 1] [-Warray-bounds]

__builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • Loading branch information
sats0k committed Jan 8, 2022
1 parent 5338a2c commit 4163e97
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ class CBase58Data {
}

std::string ToString() const {
std::vector<unsigned char> vch(1, nVersion);
std::vector<unsigned char> vch;
vch.resize(1, nVersion);
vch.shrink_to_fit();
vch.insert(vch.end(), vchData.begin(), vchData.end());
return EncodeBase58Check(vch);
}
Expand Down

3 comments on commit 4163e97

@ghostlander
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shrink_to_fit() is C++11. Need a C++03 compatible replacement. Maybe swapping the vector with itself shuts the compiler up. Could you try this code?

std::vector<uchar> vch;
vch.resize(1, nVersion);
vch.swap(vch);

@sats0k
Copy link
Contributor Author

@sats0k sats0k commented on 4163e97 Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and it works also.

@ghostlander
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, committed in 1b3f49f

Please sign in to comment.