aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorMarcoFalke <[email protected]>2019-12-16 19:10:52 -0500
committerMarcoFalke <[email protected]>2019-12-16 19:10:58 -0500
commit03dfa36641077033ffebf8b431945bfc503632a9 (patch)
tree832a046dcc171d260be5a07f87df39d766a5e9f2 /src/util
parentMerge #17593: test: move more utility functions into test utility library (diff)
parenttests: Add fuzzing harness for various hex related functions (diff)
downloaddiscoin-03dfa36641077033ffebf8b431945bfc503632a9.tar.xz
discoin-03dfa36641077033ffebf8b431945bfc503632a9.zip
Merge #17229: tests: Add fuzzing harnesses for various Base{32,58,64} and hex related functions
c18405732e38eadb2c47533c3f982f4605fbfd9a tests: Add fuzzing harness for various hex related functions (practicalswift) 526dd78bedcebcf170ce13349eb3e9fc7fbf39bb tests: Add fuzzing harness for various Base{32,58,64} related functions (practicalswift) 32e27129ff26c7cc10321652d5d2678876081983 util: Move TrimString(...). Introduce default pattern (trims whitespace). Add NODISCARD. (practicalswift) 22d9bae36f2a164acf35765231f1d93364c1c4a9 tests: Add corpora suppression (FUZZERS_MISSING_CORPORA) for fuzzers missing in https://github.com/bitcoin-core/qa-assets/tree/master/fuzz_seed_corpus (practicalswift) Pull request description: Add fuzzing harnesses for various Base{32,58,64} and hex related functions. **Testing this PR** Run: ``` $ CC=clang CXX=clang++ ./configure --enable-fuzz \ --with-sanitizers=address,fuzzer,undefined $ make $ src/test/fuzz/base_encode_decode … $ src/test/fuzz/hex … ``` ACKs for top commit: MarcoFalke: ACK c18405732e38eadb2c47533c3f982f4605fbfd9a 🔁 Tree-SHA512: 4fcbe4f641fc553e43fd5c3c40a6beec0d2ce90c5ffc718213b37fc18aba4c055e51e26f93d01ea1248fd89473d07c9dce77db7f014b47d3abd045f61b5f1905
Diffstat (limited to 'src/util')
-rw-r--r--src/util/string.h10
-rw-r--r--src/util/system.cpp11
2 files changed, 11 insertions, 10 deletions
diff --git a/src/util/string.h b/src/util/string.h
index c6fa08e5b..3db8fc8b9 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -11,6 +11,16 @@
#include <string>
#include <vector>
+NODISCARD inline std::string TrimString(const std::string& str, const std::string& pattern = " \f\n\r\t\v")
+{
+ std::string::size_type front = str.find_first_not_of(pattern);
+ if (front == std::string::npos) {
+ return std::string();
+ }
+ std::string::size_type end = str.find_last_not_of(pattern);
+ return str.substr(front, end - front + 1);
+}
+
/**
* Join a list of items
*
diff --git a/src/util/system.cpp b/src/util/system.cpp
index 563ff6a54..95458672e 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -7,6 +7,7 @@
#include <chainparamsbase.h>
#include <util/strencodings.h>
+#include <util/string.h>
#include <util/translation.h>
@@ -679,16 +680,6 @@ fs::path GetConfigFile(const std::string& confPath)
return AbsPathForConfigVal(fs::path(confPath), false);
}
-static std::string TrimString(const std::string& str, const std::string& pattern)
-{
- std::string::size_type front = str.find_first_not_of(pattern);
- if (front == std::string::npos) {
- return std::string();
- }
- std::string::size_type end = str.find_last_not_of(pattern);
- return str.substr(front, end - front + 1);
-}
-
static bool GetConfigOptions(std::istream& stream, const std::string& filepath, std::string& error, std::vector<std::pair<std::string, std::string>>& options, std::list<SectionInfo>& sections)
{
std::string str, prefix;