]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Fix number of bytes to be zeroed when spawn entity
authorDimitrian <dimitrian.tkachenko@gmail.com>
Tue, 7 Feb 2023 21:12:29 +0000 (16:12 -0500)
committerDimitrian <dimitrian.tkachenko@gmail.com>
Tue, 7 Feb 2023 21:12:29 +0000 (16:12 -0500)
In `qcvm` when zeroing memory for new entitydata wrong number of bytes used.
This leads to crash with the error:`malloc(): invalid size (unsorted)`.

Use `prog->entityfields * sizeof(qcint_t)`
instead of `sz * sizeof(qcint_t)`.

exec.cpp

index 387923f27b3c9d86f7cf772085ba2740a689087a..7c82d64efa38d7295f2ede1f6b920cc4257fb510 100644 (file)
--- a/exec.cpp
+++ b/exec.cpp
@@ -212,7 +212,7 @@ static qcint_t prog_spawn_entity(qc_program_t *prog) {
     size_t sz = prog->entitydata.size();
     prog->entitydata.resize(sz + prog->entityfields);
     data = (char*)&prog->entitydata[sz];
-    memset(data, 0, sz * sizeof(qcint_t));
+    memset(data, 0, prog->entityfields * sizeof(qcint_t));
 
     return e;
 }