Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions charadatamanger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,21 @@ void CharaDataManger::loadCharaData()
jsonArray = charaObject.value("faceChara").toArray();
}

int allocSize = qMax(faceSize, jsonArray.size());
if (allocSize <= 0) {
qWarning() << "Invalid face data size, skipping:" << chara;
continue;
}
float *faceChara = static_cast<float *>(
malloc(sizeof(float) * static_cast<unsigned long>(faceSize)));
for (int i = 0; i < jsonArray.size(); i++) {
malloc(sizeof(float) * static_cast<unsigned long>(allocSize)));
if (faceChara == nullptr) {
qWarning() << "Failed to allocate face data, skipping:" << chara;
continue;
}
for (int i = 0; i < jsonArray.size() && i < allocSize; i++) {
faceChara[i] = jsonArray[i].toString().toFloat();
}
m_charaData[chara] = QPair<int, float *>(faceSize, faceChara);
m_charaData[chara] = QPair<int, float *>(allocSize, faceChara);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Uninitialized features corrupt templates

When a stored entry has a positive faceCharaSize greater than its faceChara array length, loadCharaData() allocates faceSize elements but initializes only the array entries, then records allocSize as the template length. saveCharaData() serializes the uninitialized tail, and getCharaData() copies it for verification, corrupting templates and producing unreliable recognition results.

Initialize every allocated element before recording allocSize as the template length.

Prompt for AI agents
In `charadatamanger.cpp` at line 88:

**Uninitialized features corrupt templates**

When a stored entry has a positive `faceCharaSize` greater than its `faceChara` array length, `loadCharaData()` allocates `faceSize` elements but initializes only the array entries, then records `allocSize` as the template length. `saveCharaData()` serializes the uninitialized tail, and `getCharaData()` copies it for verification, corrupting templates and producing unreliable recognition results.

Initialize every allocated element before recording `allocSize` as the template length.

}
}

Expand Down
Loading