Resolve code analysis warnings

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2025-03-28 17:28:19 +01:00
parent 5fc35751a3
commit 91c9a71a5d
5 changed files with 36 additions and 34 deletions

View File

@ -16,6 +16,7 @@ namespace UnitTests
{ {
stdex::utf32_t tmp[0x100]; stdex::utf32_t tmp[0x100];
stdex::strncpy(tmp, u"This is a 🐔Test🐮."); stdex::strncpy(tmp, u"This is a 🐔Test🐮.");
tmp[_countof(tmp) - 1] = 0;
Assert::IsTrue(stdex::strcmp(U"This is a 🐔Test🐮.", tmp) == 0); Assert::IsTrue(stdex::strcmp(U"This is a 🐔Test🐮.", tmp) == 0);
} }

View File

@ -31,9 +31,9 @@ namespace stdex
_In_ int flags = stdex::parser::match_default) _In_ int flags = stdex::parser::match_default)
{ {
_Unreferenced_(flags); _Unreferenced_(flags);
stdex_assert(text || start + 17 >= end); stdex_assert(text || start >= end);
if (start + 17 < end && if (start < end && start + 17 < end &&
text[start + 0] == 'u' && text[start] == 'u' &&
text[start + 1] == 'n' && text[start + 1] == 'n' &&
text[start + 2] == 't' && text[start + 2] == 't' &&
text[start + 3] == 'r' && text[start + 3] == 'r' &&
@ -73,9 +73,9 @@ namespace stdex
_In_ int flags = stdex::parser::match_default) _In_ int flags = stdex::parser::match_default)
{ {
_Unreferenced_(flags); _Unreferenced_(flags);
stdex_assert(text || start + 1 >= end); stdex_assert(text || start >= end);
if (start + 1 < end && if (start < end && start + 1 < end &&
text[start + 0] == '\r' && text[start] == '\r' &&
text[start + 1] == '\n') text[start + 1] == '\n')
{ {
this->interval.end = (this->interval.start = start) + 2; this->interval.end = (this->interval.start = start) + 2;

View File

@ -4961,7 +4961,7 @@ namespace stdex
uint32_t nominator; uint32_t nominator;
this->interval.end = start; this->interval.end = start;
if (this->interval.end + 1 >= end || if (this->interval.end >= end || this->interval.end + 1 >= end ||
(case_insensitive ? ctype.toupper(text[this->interval.end]) : text[this->interval.end]) != 'R' || (case_insensitive ? ctype.toupper(text[this->interval.end]) : text[this->interval.end]) != 'R' ||
(case_insensitive ? ctype.toupper(text[this->interval.end + 1]) : text[this->interval.end + 1]) != 'F') (case_insensitive ? ctype.toupper(text[this->interval.end + 1]) : text[this->interval.end + 1]) != 'F')
goto error; // incomplete or wrong reference ID goto error; // incomplete or wrong reference ID
@ -5199,7 +5199,7 @@ namespace stdex
const bool case_insensitive = flags & match_case_insensitive ? true : false; const bool case_insensitive = flags & match_case_insensitive ? true : false;
this->interval.end = start; this->interval.end = start;
if (this->interval.end + 1 >= end || if (this->interval.end >= end || this->interval.end + 1 >= end ||
(case_insensitive ? ctype.toupper(text[this->interval.end]) : text[this->interval.end]) != 'S' || (case_insensitive ? ctype.toupper(text[this->interval.end]) : text[this->interval.end]) != 'S' ||
(case_insensitive ? ctype.toupper(text[this->interval.end + 1]) : text[this->interval.end + 1]) != 'I') (case_insensitive ? ctype.toupper(text[this->interval.end + 1]) : text[this->interval.end + 1]) != 'I')
goto error; // incomplete or wrong reference ID goto error; // incomplete or wrong reference ID
@ -5894,7 +5894,7 @@ namespace stdex
_In_ int flags = match_default) _In_ int flags = match_default)
{ {
stdex_assert(text || start >= end); stdex_assert(text || start >= end);
if (start + 2 < end && if (start < end && start + 2 < end &&
text[start] == '*' && text[start] == '*' &&
text[start + 1] == '/' && text[start + 1] == '/' &&
text[start + 2] == '*') text[start + 2] == '*')
@ -6090,7 +6090,7 @@ namespace stdex
for (;;) { for (;;) {
if (this->interval.end < end && text[this->interval.end]) { if (this->interval.end < end && text[this->interval.end]) {
if ('0' <= text[this->interval.end] && text[this->interval.end] <= '9') { if ('0' <= text[this->interval.end] && text[this->interval.end] <= '9') {
size_t _value = static_cast<size_t>(value) * 10 + static_cast<size_t>(text[this->interval.end] - '0'); size_t _value = static_cast<size_t>(value) * 10 + text[this->interval.end] - '0';
if (_value > UINT16_MAX) { if (_value > UINT16_MAX) {
value = 0; value = 0;
this->interval.invalidate(); this->interval.invalidate();
@ -6472,7 +6472,7 @@ namespace stdex
for (;;) { for (;;) {
if (this->interval.end < end && text[this->interval.end]) { if (this->interval.end < end && text[this->interval.end]) {
if ('0' <= text[this->interval.end] && text[this->interval.end] <= '9') { if ('0' <= text[this->interval.end] && text[this->interval.end] <= '9') {
celi_del = celi_del * 10 + static_cast<size_t>(text[this->interval.end] - '0'); celi_del = celi_del * 10 + text[this->interval.end] - '0';
this->interval.end++; this->interval.end++;
} }
else if (text[this->interval.end] == '.') { else if (text[this->interval.end] == '.') {
@ -6480,7 +6480,7 @@ namespace stdex
for (;;) { for (;;) {
if (this->interval.end < end && text[this->interval.end]) { if (this->interval.end < end && text[this->interval.end]) {
if ('0' <= text[this->interval.end] && text[this->interval.end] <= '9') { if ('0' <= text[this->interval.end] && text[this->interval.end] <= '9') {
decimalni_del = decimalni_del * 10 + static_cast<size_t>(text[this->interval.end] - '0'); decimalni_del = decimalni_del * 10 + text[this->interval.end] - '0';
decimalni_del_n *= 10; decimalni_del_n *= 10;
this->interval.end++; this->interval.end++;
} }
@ -7368,8 +7368,8 @@ namespace stdex
_In_ int flags = match_multiline) _In_ int flags = match_multiline)
{ {
_Unreferenced_(flags); _Unreferenced_(flags);
stdex_assert(text || start + 1 >= end); stdex_assert(text || start >= end);
if (start + 1 < end && if (start < end && start + 1 < end &&
text[start] == '/' && text[start] == '/' &&
text[start + 1] == '*') text[start + 1] == '*')
{ {
@ -7419,8 +7419,8 @@ namespace stdex
_In_ int flags = match_multiline) _In_ int flags = match_multiline)
{ {
_Unreferenced_(flags); _Unreferenced_(flags);
stdex_assert(text || start + 3 >= end); stdex_assert(text || start >= end);
if (start + 3 < end && if (start < end && start + 3 < end &&
text[start] == '<' && text[start] == '<' &&
text[start + 1] == '!' && text[start + 1] == '!' &&
text[start + 2] == '-' && text[start + 2] == '-' &&
@ -7457,8 +7457,8 @@ namespace stdex
_In_ int flags = match_multiline) _In_ int flags = match_multiline)
{ {
_Unreferenced_(flags); _Unreferenced_(flags);
stdex_assert(text || start + 2 >= end); stdex_assert(text || start >= end);
if (start + 2 < end && if (start < end && start + 2 < end &&
text[start] == '-' && text[start] == '-' &&
text[start + 1] == '-' && text[start + 1] == '-' &&
text[start + 2] == '>') text[start + 2] == '>')
@ -7571,8 +7571,8 @@ namespace stdex
{ {
_Unreferenced_(flags); _Unreferenced_(flags);
this->interval.end = start; this->interval.end = start;
stdex_assert(text || this->interval.end + 3 >= end); stdex_assert(text || this->interval.end >= end);
if (this->interval.end + 3 < end && if (this->interval.end < end && this->interval.end + 3 < end &&
(text[this->interval.end] == 'u' || text[this->interval.end] == 'U') && (text[this->interval.end] == 'u' || text[this->interval.end] == 'U') &&
(text[this->interval.end + 1] == 'r' || text[this->interval.end + 1] == 'R') && (text[this->interval.end + 1] == 'r' || text[this->interval.end + 1] == 'R') &&
(text[this->interval.end + 2] == 'l' || text[this->interval.end + 2] == 'L') && (text[this->interval.end + 2] == 'l' || text[this->interval.end + 2] == 'L') &&
@ -7681,8 +7681,8 @@ namespace stdex
{ {
_Unreferenced_(flags); _Unreferenced_(flags);
this->interval.end = start; this->interval.end = start;
stdex_assert(text || this->interval.end + 6 >= end); stdex_assert(text || this->interval.end >= end);
if (this->interval.end + 6 < end && if (this->interval.end < end && this->interval.end + 6 < end &&
text[this->interval.end] == '@' && text[this->interval.end] == '@' &&
(text[this->interval.end + 1] == 'i' || text[this->interval.end + 1] == 'I') && (text[this->interval.end + 1] == 'i' || text[this->interval.end + 1] == 'I') &&
(text[this->interval.end + 2] == 'm' || text[this->interval.end + 2] == 'M') && (text[this->interval.end + 2] == 'm' || text[this->interval.end + 2] == 'M') &&
@ -7811,7 +7811,7 @@ namespace stdex
// Skip whitespace. // Skip whitespace.
for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++); for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++);
if (this->interval.end + 7 < end && if (this->interval.end < end && this->interval.end + 7 < end &&
(text[this->interval.end] == 'c' || text[this->interval.end] == 'C') && (text[this->interval.end] == 'c' || text[this->interval.end] == 'C') &&
(text[this->interval.end + 1] == 'h' || text[this->interval.end + 1] == 'H') && (text[this->interval.end + 1] == 'h' || text[this->interval.end + 1] == 'H') &&
(text[this->interval.end + 2] == 'a' || text[this->interval.end + 2] == 'A') && (text[this->interval.end + 2] == 'a' || text[this->interval.end + 2] == 'A') &&
@ -8074,7 +8074,7 @@ namespace stdex
else if (text[this->interval.end] == '!') { else if (text[this->interval.end] == '!') {
// <!... // <!...
this->interval.end++; this->interval.end++;
if (this->interval.end + 1 < end && if (this->interval.end < end && this->interval.end + 1 < end &&
text[this->interval.end] == '-' && text[this->interval.end] == '-' &&
text[this->interval.end + 1] == '-') text[this->interval.end + 1] == '-')
{ {
@ -8149,7 +8149,7 @@ namespace stdex
this->attributes.clear(); this->attributes.clear();
for (;;) { for (;;) {
if (this->type == html_sequence_t::element_start && if (this->type == html_sequence_t::element_start &&
this->interval.end + 1 < end && this->interval.end < end && this->interval.end + 1 < end &&
text[this->interval.end] == '/' && text[this->interval.end] == '/' &&
text[this->interval.end + 1] == '>') text[this->interval.end + 1] == '>')
{ {
@ -8166,7 +8166,7 @@ namespace stdex
break; break;
} }
if (this->type == html_sequence_t::declaration && if (this->type == html_sequence_t::declaration &&
this->interval.end + 1 < end && this->interval.end < end && this->interval.end + 1 < end &&
text[this->interval.end] == '!' && text[this->interval.end] == '!' &&
text[this->interval.end + 1] == '>') text[this->interval.end + 1] == '>')
{ {
@ -8175,7 +8175,7 @@ namespace stdex
break; break;
} }
if (this->type == html_sequence_t::declaration && if (this->type == html_sequence_t::declaration &&
this->interval.end + 1 < end && this->interval.end < end && this->interval.end + 1 < end &&
text[this->interval.end] == '-' && text[this->interval.end] == '-' &&
text[this->interval.end + 1] == '-') text[this->interval.end + 1] == '-')
{ {
@ -8285,8 +8285,8 @@ namespace stdex
_In_ int flags = match_multiline) _In_ int flags = match_multiline)
{ {
_Unreferenced_(flags); _Unreferenced_(flags);
stdex_assert(text || start + 2 >= end); stdex_assert(text || start >= end);
if (start + 2 < end && if (start < end && start + 2 < end &&
text[start] == '<' && text[start] == '<' &&
text[start + 1] == '!' && text[start + 1] == '!' &&
text[start + 2] == '[') text[start + 2] == '[')
@ -8342,8 +8342,8 @@ namespace stdex
_In_ int flags = match_multiline) _In_ int flags = match_multiline)
{ {
_Unreferenced_(flags); _Unreferenced_(flags);
stdex_assert(text || start + 2 >= end); stdex_assert(text || start >= end);
if (start + 2 < end && if (start < end && start + 2 < end &&
text[start] == ']' && text[start] == ']' &&
text[start + 1] == ']' && text[start + 1] == ']' &&
text[start + 2] == '>') text[start + 2] == '>')

View File

@ -1195,7 +1195,8 @@ namespace stdex
case op_t::flush: case op_t::flush:
source->flush(); source->flush();
break; break;
case op_t::noop:; case op_t::noop:
break;
} }
op = op_t::noop; op = op_t::noop;
lk.unlock(); lk.unlock();

View File

@ -1840,7 +1840,7 @@ namespace stdex
/// ///
template <class T1, size_t N1, class T2, size_t N2> template <class T1, size_t N1, class T2, size_t N2>
size_t strncpy( size_t strncpy(
_Out_ _Post_maybez_ T1(&dst)[N1], _Inout_ _Post_maybez_ T1(&dst)[N1],
_In_ const T2(&src)[N2]) _In_ const T2(&src)[N2])
{ {
return strncpy(dst, N1, src, N2); return strncpy(dst, N1, src, N2);
@ -2823,7 +2823,7 @@ namespace stdex
} }
size_t offset = str.size(); size_t offset = str.size();
str.resize(offset + count); str.resize(offset + count);
if (vsnprintf(&str[offset], count + 1, format, locale, arg) != count) _Unlikely_ if (vsnprintf(&str[offset], static_cast<size_t>(count) + 1, format, locale, arg) != count) _Unlikely_
throw std::runtime_error("failed to format string"); throw std::runtime_error("failed to format string");
#else #else
size_t offset = str.size(); size_t offset = str.size();