Skip to content

Commit

Permalink
Ensure that convertWCStringToQString asserts only, when the string is…
Browse files Browse the repository at this point in the history
… longer, than the specified length
  • Loading branch information
JoergAtGithub committed Feb 26, 2023
1 parent 1b99e57 commit dabdeb2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/util/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ inline std::size_t wcsnlen_s(
/// See also: QString::fromWCharArray()
inline QString convertWCStringToQString(
const wchar_t* wcs,
std::size_t len) {
std::size_t maxLen) {
if (!wcs) {
DEBUG_ASSERT(len == 0);
DEBUG_ASSERT(maxLen == 0);
return QString();
}
DEBUG_ASSERT(wcsnlen_s(wcs, len) == len);

std::size_t len = wcsnlen(wcs, maxLen + 1);
// Assert when the string wcs has more characters than the specified maximum size
DEBUG_ASSERT(len <= maxLen);
const auto ilen = static_cast<int>(len);
DEBUG_ASSERT(ilen >= 0); // unsigned -> signed
switch (sizeof(wchar_t)) {
Expand Down

0 comments on commit dabdeb2

Please sign in to comment.