summaryrefslogtreecommitdiff
path: root/include/multipart_parser.hpp
diff options
context:
space:
mode:
authorPatrick Williams <patrick@stwcx.xyz>2023-05-11 03:40:27 +0300
committerPatrick Williams <patrick@stwcx.xyz>2023-05-11 06:24:35 +0300
commit0e31e95217e477620cba456393368183dea55d75 (patch)
tree52e36ebf7f1b6478e2fb7fe2a299580cc2228c72 /include/multipart_parser.hpp
parent97c920c5ebb6407f1d5e08b55029c3dfe53ac8cc (diff)
downloadbmcweb-0e31e95217e477620cba456393368183dea55d75.tar.xz
multipart-parser: fix clang-tidy issues
``` ../include/multipart_parser.hpp:77:21: error: 'buffer' is an unsafe pointer used for buffer access [-Werror,-Wunsafe-buffer-usage] const char* buffer = req.body().data(); ../include/multipart_parser.hpp:246:38: error: 'buffer' is an unsafe pointer used for buffer access [-Werror,-Wunsafe-buffer-usage] void skipNonBoundary(const char* buffer, size_t len, size_t boundaryEnd, ``` Signed-off-by: Patrick Williams <patrick@stwcx.xyz> Change-Id: Iad3b4b241ec75a152e240755a307a970798079fb
Diffstat (limited to 'include/multipart_parser.hpp')
-rw-r--r--include/multipart_parser.hpp29
1 files changed, 11 insertions, 18 deletions
diff --git a/include/multipart_parser.hpp b/include/multipart_parser.hpp
index abc1657fcb..5ac196dd31 100644
--- a/include/multipart_parser.hpp
+++ b/include/multipart_parser.hpp
@@ -74,13 +74,12 @@ class MultipartParser
lookbehind.resize(boundary.size() + 8);
state = State::START;
- const char* buffer = req.body().data();
- size_t len = req.body().size();
+ const std::string& buffer = req.body();
+ size_t len = buffer.size();
char cl = 0;
for (size_t i = 0; i < len; i++)
{
- // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
char c = buffer[i];
switch (state)
{
@@ -142,8 +141,7 @@ class MultipartParser
return ParserError::ERROR_EMPTY_HEADER;
}
- // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
- currentHeaderName.append(buffer + headerFieldMark,
+ currentHeaderName.append(&buffer[headerFieldMark],
i - headerFieldMark);
state = State::HEADER_VALUE_START;
break;
@@ -165,8 +163,7 @@ class MultipartParser
case State::HEADER_VALUE:
if (c == cr)
{
- // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
- std::string_view value(buffer + headerValueMark,
+ std::string_view value(&buffer[headerValueMark],
i - headerValueMark);
mime_fields.rbegin()->fields.set(currentHeaderName,
value);
@@ -199,13 +196,11 @@ class MultipartParser
{
if (index == 0)
{
- skipNonBoundary(buffer, len, boundary.size() - 1, i);
-
- // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
+ skipNonBoundary(buffer, boundary.size() - 1, i);
c = buffer[i];
}
- const ParserError ec = processPartData(buffer, i, c);
- if (ec != ParserError::PARSER_SUCCESS)
+ if (auto ec = processPartData(buffer, i, c);
+ ec != ParserError::PARSER_SUCCESS)
{
return ec;
}
@@ -246,13 +241,12 @@ class MultipartParser
return boundaryIndex[static_cast<unsigned char>(c)];
}
- void skipNonBoundary(const char* buffer, size_t len, size_t boundaryEnd,
+ void skipNonBoundary(const std::string& buffer, size_t boundaryEnd,
size_t& i)
{
// boyer-moore derived algorithm to safely skip non-boundary data
- while (i + boundary.size() <= len)
+ while (i + boundary.size() <= buffer.length())
{
- // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
if (isBoundaryChar(buffer[i + boundaryEnd]))
{
break;
@@ -261,7 +255,7 @@ class MultipartParser
}
}
- ParserError processPartData(const char* buffer, size_t& i, char c)
+ ParserError processPartData(const std::string& buffer, size_t& i, char c)
{
size_t prevIndex = index;
@@ -271,8 +265,7 @@ class MultipartParser
{
if (index == 0)
{
- // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
- const char* start = buffer + partDataMark;
+ const char* start = &buffer[partDataMark];
size_t size = i - partDataMark;
mime_fields.rbegin()->content += std::string_view(start,
size);