Skip to content

Commit f6bd506

Browse files
rename: ValidAsCString -> ContainsNoNUL
1 parent 0ce624f commit f6bd506

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

src/base58.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ std::string EncodeBase58(Span<const unsigned char> input)
126126

127127
bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret_len)
128128
{
129-
if (!ValidAsCString(str)) {
129+
if (!ContainsNoNUL(str)) {
130130
return false;
131131
}
132132
return DecodeBase58(str.c_str(), vchRet, max_ret_len);
@@ -160,7 +160,7 @@ std::string EncodeBase58Check(Span<const unsigned char> input)
160160

161161
bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret)
162162
{
163-
if (!ValidAsCString(str)) {
163+
if (!ContainsNoNUL(str)) {
164164
return false;
165165
}
166166
return DecodeBase58Check(str.c_str(), vchRet, max_ret);

src/netaddress.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static void Checksum(Span<const uint8_t> addr_pubkey, uint8_t (&checksum)[CHECKS
211211

212212
bool CNetAddr::SetSpecial(const std::string& addr)
213213
{
214-
if (!ValidAsCString(addr)) {
214+
if (!ContainsNoNUL(addr)) {
215215
return false;
216216
}
217217

src/netbase.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ std::vector<std::string> GetNetworkNames(bool append_unroutable)
144144

145145
static std::vector<CNetAddr> LookupIntern(const std::string& name, unsigned int nMaxSolutions, bool fAllowLookup, DNSLookupFn dns_lookup_function)
146146
{
147-
if (!ValidAsCString(name)) return {};
147+
if (!ContainsNoNUL(name)) return {};
148148
{
149149
CNetAddr addr;
150150
// From our perspective, onion addresses are not hostnames but rather
@@ -173,7 +173,7 @@ static std::vector<CNetAddr> LookupIntern(const std::string& name, unsigned int
173173

174174
std::vector<CNetAddr> LookupHost(const std::string& name, unsigned int nMaxSolutions, bool fAllowLookup, DNSLookupFn dns_lookup_function)
175175
{
176-
if (!ValidAsCString(name)) return {};
176+
if (!ContainsNoNUL(name)) return {};
177177
std::string strHost = name;
178178
if (strHost.empty()) return {};
179179
if (strHost.front() == '[' && strHost.back() == ']') {
@@ -191,7 +191,7 @@ std::optional<CNetAddr> LookupHost(const std::string& name, bool fAllowLookup, D
191191

192192
std::vector<CService> Lookup(const std::string& name, uint16_t portDefault, bool fAllowLookup, unsigned int nMaxSolutions, DNSLookupFn dns_lookup_function)
193193
{
194-
if (name.empty() || !ValidAsCString(name)) {
194+
if (name.empty() || !ContainsNoNUL(name)) {
195195
return {};
196196
}
197197
uint16_t port{portDefault};
@@ -216,7 +216,7 @@ std::optional<CService> Lookup(const std::string& name, uint16_t portDefault, bo
216216

217217
CService LookupNumeric(const std::string& name, uint16_t portDefault, DNSLookupFn dns_lookup_function)
218218
{
219-
if (!ValidAsCString(name)) {
219+
if (!ContainsNoNUL(name)) {
220220
return {};
221221
}
222222
// "1.2:345" will fail to resolve the ip, but will still set the port.
@@ -668,7 +668,7 @@ bool ConnectThroughProxy(const Proxy& proxy, const std::string& strDest, uint16_
668668

669669
bool LookupSubNet(const std::string& subnet_str, CSubNet& subnet_out)
670670
{
671-
if (!ValidAsCString(subnet_str)) {
671+
if (!ContainsNoNUL(subnet_str)) {
672672
return false;
673673
}
674674

src/test/fuzz/string.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bool LegacyParsePrechecks(const std::string& str)
4040
return false;
4141
if (str.size() >= 1 && (IsSpace(str[0]) || IsSpace(str[str.size() - 1]))) // No padding allowed
4242
return false;
43-
if (!ValidAsCString(str)) // No embedded NUL characters allowed
43+
if (!ContainsNoNUL(str)) // No embedded NUL characters allowed
4444
return false;
4545
return true;
4646
}
@@ -185,7 +185,7 @@ FUZZ_TARGET(string)
185185
(void)TrimString(random_string_1);
186186
(void)TrimString(random_string_1, random_string_2);
187187
(void)urlDecode(random_string_1);
188-
(void)ValidAsCString(random_string_1);
188+
(void)ContainsNoNUL(random_string_1);
189189
(void)_(random_string_1.c_str());
190190
try {
191191
throw scriptnum_error{random_string_1};

src/util/moneystr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ std::string FormatMoney(const CAmount n)
4040

4141
std::optional<CAmount> ParseMoney(const std::string& money_string)
4242
{
43-
if (!ValidAsCString(money_string)) {
43+
if (!ContainsNoNUL(money_string)) {
4444
return std::nullopt;
4545
}
4646
const std::string str = TrimString(money_string);

src/util/string.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ inline std::string MakeUnorderedList(const std::vector<std::string>& items)
9999
/**
100100
* Check if a string does not contain any embedded NUL (\0) characters
101101
*/
102-
[[nodiscard]] inline bool ValidAsCString(std::string_view str) noexcept
102+
[[nodiscard]] inline bool ContainsNoNUL(std::string_view str) noexcept
103103
{
104104
for (auto c : str) {
105105
if (c == 0) return false;

0 commit comments

Comments
 (0)