From 090b7600b78afc12337cf29d5ea33cfd78d6a07f Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 14 Jun 2021 10:24:18 -0700 Subject: [PATCH] [string] use `StringFind()` in core modules (#6725) This commit replaces uses of `strchr()` with `StringFind()`. --- src/core/coap/coap_message.cpp | 3 ++- src/core/utils/parse_cmdline.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/coap/coap_message.cpp b/src/core/coap/coap_message.cpp index 3f34b5d71..56c90d210 100644 --- a/src/core/coap/coap_message.cpp +++ b/src/core/coap/coap_message.cpp @@ -39,6 +39,7 @@ #include "common/encoding.hpp" #include "common/instance.hpp" #include "common/random.hpp" +#include "common/string.hpp" namespace ot { namespace Coap { @@ -229,7 +230,7 @@ Error Message::AppendUriPathOptions(const char *aUriPath) const char *cur = aUriPath; const char *end; - while ((end = strchr(cur, '/')) != nullptr) + while ((end = StringFind(cur, '/')) != nullptr) { SuccessOrExit(error = AppendOption(kOptionUriPath, static_cast(end - cur), cur)); cur = end + 1; diff --git a/src/core/utils/parse_cmdline.cpp b/src/core/utils/parse_cmdline.cpp index e2f5f5a91..1893aeb36 100644 --- a/src/core/utils/parse_cmdline.cpp +++ b/src/core/utils/parse_cmdline.cpp @@ -37,6 +37,7 @@ #include "common/code_utils.hpp" #include "common/numeric_limits.hpp" +#include "common/string.hpp" #include "net/ip6_address.hpp" namespace ot { @@ -258,7 +259,7 @@ Error ParseAsIp6Prefix(const char *aString, otIp6Prefix &aPrefix) char string[kMaxIp6AddressStringSize]; const char *prefixLengthStr; - prefixLengthStr = strchr(aString, '/'); + prefixLengthStr = StringFind(aString, '/'); VerifyOrExit(prefixLengthStr != nullptr); VerifyOrExit(prefixLengthStr - aString < static_cast(sizeof(string)));