Skip to content

Commit 009d16a

Browse files
committed
[#628] Fix some issues caught by MISRA 2023 rule 7.0.3
1 parent 85568ad commit 009d16a

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

compiler/extensions/cpp/runtime/src/zserio/CppRuntimeException.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void CppRuntimeException::appendImpl(Span<const char> message)
3939
(void)std::copy(message.begin(), message.end(), m_buffer.begin() + m_len);
4040
m_len += message.size();
4141
}
42-
m_buffer.at(m_len) = 0;
42+
m_buffer.at(m_len) = '\0';
4343
}
4444

4545
CppRuntimeException& operator<<(CppRuntimeException& exception, const char* message)

compiler/extensions/cpp/runtime/src/zserio/JsonDecoder.h

+12-10
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class BasicJsonDecoder : public AllocatorHolder<ALLOC>
146146
DecoderResult decodeString(StringView input);
147147
static bool decodeUnicodeEscape(
148148
StringView input, StringView::const_iterator& inputIt, string<ALLOC>& value);
149-
static char decodeHex(char character);
149+
static int32_t decodeHex(char character);
150150
size_t checkNumber(StringView input, bool& isDouble, bool& isSigned);
151151
DecoderResult decodeNumber(StringView input);
152152
DecoderResult decodeSigned(StringView input);
@@ -277,8 +277,9 @@ bool BasicJsonDecoder<ALLOC>::decodeUnicodeEscape(
277277
{
278278
return false;
279279
}
280-
const char char1 = decodeHex(*inputIt++);
281-
if (char1 == -1)
280+
281+
const int32_t hex1 = decodeHex(*inputIt++);
282+
if (hex1 < 0)
282283
{
283284
return false;
284285
}
@@ -287,30 +288,31 @@ bool BasicJsonDecoder<ALLOC>::decodeUnicodeEscape(
287288
{
288289
return false;
289290
}
290-
const char char2 = decodeHex(*inputIt++);
291-
if (char2 == -1)
291+
292+
const int32_t hex2 = decodeHex(*inputIt++);
293+
if (hex2 < 0)
292294
{
293295
return false;
294296
}
295297

296-
value.push_back(static_cast<char>((static_cast<uint32_t>(char1) << 4U) | static_cast<uint32_t>(char2)));
298+
value.push_back(static_cast<char>((static_cast<uint32_t>(hex1) << 4U) | static_cast<uint32_t>(hex2)));
297299
return true;
298300
}
299301

300302
template <typename ALLOC>
301-
char BasicJsonDecoder<ALLOC>::decodeHex(char character)
303+
int32_t BasicJsonDecoder<ALLOC>::decodeHex(char character)
302304
{
303305
if (character >= '0' && character <= '9')
304306
{
305-
return static_cast<char>(character - '0');
307+
return static_cast<int32_t>(character - '0');
306308
}
307309
else if (character >= 'a' && character <= 'f')
308310
{
309-
return static_cast<char>(character - 'a' + 10);
311+
return static_cast<int32_t>(character - 'a' + 10);
310312
}
311313
else if (character >= 'A' && character <= 'F')
312314
{
313-
return static_cast<char>(character - 'A' + 10);
315+
return static_cast<int32_t>(character - 'A' + 10);
314316
}
315317

316318
return -1;

0 commit comments

Comments
 (0)