fix(PIString): initialize toChar() return value and fix operator+= OOB

- toChar(): char v was uninitialized, causing UB when
  sscanf fails to match (empty string). Initialize to 0.

- operator+=(PIConstChars): loop iterated l < d.size() instead of
  l < str.size(), reading past the end of str after d.enlarge().
  This is a heap buffer overread with undefined behavior.
This commit is contained in:
2026-08-05 17:39:34 +03:00
parent ef560ccc96
commit 216109b8ed
+2 -2
View File
@@ -671,7 +671,7 @@ PIString & PIString::operator+=(const PIConstChars & str) {
if (!str.isEmpty()) { if (!str.isEmpty()) {
size_t os = d.size(); size_t os = d.size();
d.enlarge(str.size()); d.enlarge(str.size());
for (size_t l = 0; l < d.size(); ++l) { for (size_t l = 0; l < str.size(); ++l) {
d[os + l] = str[l]; d[os + l] = str[l];
} }
} }
@@ -1763,7 +1763,7 @@ PIString PIString::toLowerCase() const {
char PIString::toChar() const { char PIString::toChar() const {
char v; char v = 0;
sscanf(dataAscii(), "%c", &v); sscanf(dataAscii(), "%c", &v);
return v; return v;
} }