diff options
author | Patrick Williams <patrick@stwcx.xyz> | 2023-05-11 19:47:45 +0300 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2023-05-12 18:03:49 +0300 |
commit | 84396af956fcdf14cfc6d27e0a9684369fa30674 (patch) | |
tree | 917e2881f759ac1c09cb5c8f3f65a23ee3627191 | |
parent | 2bd4ab43be2592ffe0b1321c18d0169f010486ab (diff) | |
download | bmcweb-84396af956fcdf14cfc6d27e0a9684369fa30674.tar.xz |
log-services: fix clang-tidy warnings
A number of similar warnings about unsafe pointer arithmetic.
```
../redfish-core/lib/log_services.hpp:269:39: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage]
indexStr.data(), indexStr.data() + indexStr.size(), index);
```
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Icc4a0d2f418c76d6987ef2318b0098d30d116389
-rw-r--r-- | include/json_html_serializer.hpp | 8 | ||||
-rw-r--r-- | redfish-core/lib/log_services.hpp | 32 |
2 files changed, 16 insertions, 24 deletions
diff --git a/include/json_html_serializer.hpp b/include/json_html_serializer.hpp index f23150ebe2..8d5ed3c7c2 100644 --- a/include/json_html_serializer.hpp +++ b/include/json_html_serializer.hpp @@ -233,8 +233,6 @@ inline void dumpEscaped(std::string& out, const std::string& str) // continue processing the string state = utf8Accept; break; - - break; } default: // decode found yet incomplete multi-byte code point @@ -324,7 +322,7 @@ void dumpInteger(std::string& out, NumberType number) } // use a pointer to fill the buffer - auto bufferPtr = numberbuffer.begin(); + auto* bufferPtr = numberbuffer.begin(); const bool isNegative = std::is_same<NumberType, int64_t>::value && !(number >= 0); // see issue #755 @@ -420,7 +418,7 @@ inline void dumpfloat(std::string& out, double number, return; } - auto end = numberbuffer.begin(); + auto* end = numberbuffer.begin(); std::advance(end, len); end = std::remove(numberbuffer.begin(), end, ','); std::fill(end, numberbuffer.end(), '\0'); @@ -434,7 +432,7 @@ inline void dumpfloat(std::string& out, double number, out.append(numberbuffer.data(), static_cast<std::size_t>(len)); // determine if need to append ".0" - auto newEnd = numberbuffer.begin(); + auto* newEnd = numberbuffer.begin(); std::advance(newEnd, len + 1); const bool valueIsIntLike = diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index aeb1d191bf..c52c99ba55 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -265,8 +265,8 @@ inline static bool tsStr.remove_suffix(tsStr.size() - underscorePos); std::string_view indexStr(entryID); indexStr.remove_prefix(underscorePos + 1); - auto [ptr, ec] = std::from_chars( - indexStr.data(), indexStr.data() + indexStr.size(), index); + auto [ptr, ec] = std::from_chars(indexStr.begin(), indexStr.end(), + index); if (ec != std::errc()) { messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); @@ -274,8 +274,7 @@ inline static bool } } // Timestamp has no index - auto [ptr, ec] = std::from_chars(tsStr.data(), tsStr.data() + tsStr.size(), - timestamp); + auto [ptr, ec] = std::from_chars(tsStr.begin(), tsStr.end(), timestamp); if (ec != std::errc()) { messages::resourceNotFound(asyncResp->res, "LogEntry", entryID); @@ -2241,10 +2240,8 @@ inline void requestRoutesSystemHostLoggerLogEntry(App& app) uint64_t idInt = 0; - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - const char* end = targetID.data() + targetID.size(); - - auto [ptr, ec] = std::from_chars(targetID.data(), end, idInt); + auto [ptr, ec] = std::from_chars(&*targetID.begin(), &*targetID.end(), + idInt); if (ec == std::errc::invalid_argument || ec == std::errc::result_out_of_range) { @@ -3668,24 +3665,21 @@ inline static bool parsePostCode(const std::string& postCodeID, return false; } - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - const char* start = split[0].data() + 1; - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - const char* end = split[0].data() + split[0].size(); - auto [ptrIndex, ecIndex] = std::from_chars(start, end, index); + auto start = std::next(split[0].begin()); + auto end = split[0].end(); + auto [ptrIndex, ecIndex] = std::from_chars(&*start, &*end, index); - if (ptrIndex != end || ecIndex != std::errc()) + if (ptrIndex != &*end || ecIndex != std::errc()) { return false; } - start = split[1].data(); + start = split[1].begin(); + end = split[1].end(); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - end = split[1].data() + split[1].size(); - auto [ptrValue, ecValue] = std::from_chars(start, end, currentValue); + auto [ptrValue, ecValue] = std::from_chars(&*start, &*end, currentValue); - return ptrValue == end && ecValue == std::errc(); + return ptrValue == &*end && ecValue == std::errc(); } static bool fillPostCodeEntry( |