Enable checks for pointer arithmetic
Quite a few places we've disobeyed this rule, so simply ignore them for
now to avoid new issues popping up.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I3e518a8e8742279afb3ad1a9dad54006ed109fb1
diff --git a/include/async_resolve.hpp b/include/async_resolve.hpp
index c69fd87..0945001 100644
--- a/include/async_resolve.hpp
+++ b/include/async_resolve.hpp
@@ -80,6 +80,7 @@
}
uint16_t portNum = 0;
auto it = std::from_chars(
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
port.data(), port.data() + port.size(), portNum);
if (it.ec != std::errc())
{
diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp
index 4fbb503..5a86d09 100644
--- a/include/ibm/locks.hpp
+++ b/include/ibm/locks.hpp
@@ -535,9 +535,14 @@
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
uint8_t* q = reinterpret_cast<uint8_t*>(&resourceId2);
- BMCWEB_LOG_DEBUG << "Comparing bytes " << std::to_string(p[position]) << ","
- << std::to_string(q[position]);
- if (p[position] != q[position])
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
+ uint8_t pPosition = p[position];
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
+ uint8_t qPosition = q[position];
+
+ BMCWEB_LOG_DEBUG << "Comparing bytes " << std::to_string(pPosition) << ","
+ << std::to_string(qPosition);
+ if (pPosition != qPosition)
{
return false;
}
diff --git a/include/json_html_serializer.hpp b/include/json_html_serializer.hpp
index 3efc224..4969d27 100644
--- a/include/json_html_serializer.hpp
+++ b/include/json_html_serializer.hpp
@@ -353,6 +353,7 @@
// jump to the end to generate the string from backward
// so we later avoid reversing the result
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
bufferPtr += nChars;
// Fast int2ascii implementation inspired by "Fastware" talk by Andrei
@@ -384,6 +385,8 @@
{
std::array<char, 64> numberbuffer{{}};
char* begin = numberbuffer.data();
+
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
::nlohmann::detail::to_chars(begin, begin + numberbuffer.size(), number);
out += begin;
diff --git a/include/multipart_parser.hpp b/include/multipart_parser.hpp
index 3728311..e385558 100644
--- a/include/multipart_parser.hpp
+++ b/include/multipart_parser.hpp
@@ -79,6 +79,7 @@
for (size_t i = 0; i < len; i++)
{
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
char c = buffer[i];
switch (state)
{
@@ -139,6 +140,8 @@
{
return ParserError::ERROR_EMPTY_HEADER;
}
+
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
currentHeaderName.append(buffer + headerFieldMark,
i - headerFieldMark);
state = State::HEADER_VALUE_START;
@@ -161,6 +164,7 @@
case State::HEADER_VALUE:
if (c == cr)
{
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
std::string_view value(buffer + headerValueMark,
i - headerValueMark);
mime_fields.rbegin()->fields.set(currentHeaderName,
@@ -190,6 +194,8 @@
if (index == 0)
{
skipNonBoundary(buffer, len, boundary.size() - 1, i);
+
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
c = buffer[i];
}
processPartData(prevIndex, index, buffer, i, c, state);
@@ -229,6 +235,7 @@
// boyer-moore derived algorithm to safely skip non-boundary data
while (i + boundary.size() <= len)
{
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
if (isBoundaryChar(buffer[i + boundaryEnd]))
{
break;
@@ -248,8 +255,11 @@
{
if (index == 0)
{
- mime_fields.rbegin()->content += std::string_view(
- buffer + partDataMark, i - partDataMark);
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
+ const char* start = buffer + partDataMark;
+ size_t size = i - partDataMark;
+ mime_fields.rbegin()->content +=
+ std::string_view(start, size);
}
index++;
}
diff --git a/include/pam_authenticate.hpp b/include/pam_authenticate.hpp
index 0ce0bb4..1459ea6 100644
--- a/include/pam_authenticate.hpp
+++ b/include/pam_authenticate.hpp
@@ -24,6 +24,7 @@
for (int i = 0; i < numMsg; ++i)
{
/* Ignore all PAM messages except prompting for hidden input */
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
if (msg[i]->msg_style != PAM_PROMPT_ECHO_OFF)
{
continue;
@@ -66,6 +67,7 @@
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
*resp = reinterpret_cast<pam_response*>(ptr);
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
resp[i]->resp = pass;
return PAM_SUCCESS;