Skip to content

Commit

Permalink
[#628] Fix some issues caught by MISRA 2023 rule 7.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Mi-La committed Aug 13, 2024
1 parent 85568ad commit 009d16a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void CppRuntimeException::appendImpl(Span<const char> message)
(void)std::copy(message.begin(), message.end(), m_buffer.begin() + m_len);
m_len += message.size();
}
m_buffer.at(m_len) = 0;
m_buffer.at(m_len) = '\0';
}

CppRuntimeException& operator<<(CppRuntimeException& exception, const char* message)
Expand Down
22 changes: 12 additions & 10 deletions compiler/extensions/cpp/runtime/src/zserio/JsonDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class BasicJsonDecoder : public AllocatorHolder<ALLOC>
DecoderResult decodeString(StringView input);
static bool decodeUnicodeEscape(
StringView input, StringView::const_iterator& inputIt, string<ALLOC>& value);
static char decodeHex(char character);
static int32_t decodeHex(char character);
size_t checkNumber(StringView input, bool& isDouble, bool& isSigned);
DecoderResult decodeNumber(StringView input);
DecoderResult decodeSigned(StringView input);
Expand Down Expand Up @@ -277,8 +277,9 @@ bool BasicJsonDecoder<ALLOC>::decodeUnicodeEscape(
{
return false;
}
const char char1 = decodeHex(*inputIt++);
if (char1 == -1)

const int32_t hex1 = decodeHex(*inputIt++);
if (hex1 < 0)
{
return false;
}
Expand All @@ -287,30 +288,31 @@ bool BasicJsonDecoder<ALLOC>::decodeUnicodeEscape(
{
return false;
}
const char char2 = decodeHex(*inputIt++);
if (char2 == -1)

const int32_t hex2 = decodeHex(*inputIt++);
if (hex2 < 0)
{
return false;
}

value.push_back(static_cast<char>((static_cast<uint32_t>(char1) << 4U) | static_cast<uint32_t>(char2)));
value.push_back(static_cast<char>((static_cast<uint32_t>(hex1) << 4U) | static_cast<uint32_t>(hex2)));
return true;
}

template <typename ALLOC>
char BasicJsonDecoder<ALLOC>::decodeHex(char character)
int32_t BasicJsonDecoder<ALLOC>::decodeHex(char character)
{
if (character >= '0' && character <= '9')
{
return static_cast<char>(character - '0');
return static_cast<int32_t>(character - '0');
}
else if (character >= 'a' && character <= 'f')
{
return static_cast<char>(character - 'a' + 10);
return static_cast<int32_t>(character - 'a' + 10);
}
else if (character >= 'A' && character <= 'F')
{
return static_cast<char>(character - 'A' + 10);
return static_cast<int32_t>(character - 'A' + 10);
}

return -1;
Expand Down

0 comments on commit 009d16a

Please sign in to comment.