Skip to content

Commit 600f43c

Browse files
committed
refs: fix Valgrind issue
1 parent 7c6c0eb commit 600f43c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

generator/c2refs.c2

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ fn void Files.dump(const Files* f, bool verbose) {
276276
// ------ Lengths ------
277277

278278
type Lengths struct {
279-
u32 total_size; // of whole Files
279+
u32 total_size; // of whole Files
280280
u32 count; // current number of entries
281281
u32 cap; // max number of entries
282282
u8[0] lengths;
@@ -293,6 +293,9 @@ fn Lengths* Lengths.create(u32 max_lengths) {
293293
f.total_size = size;
294294
f.count = 0;
295295
f.cap = max_lengths;
296+
// set last byte to avoid write of unitialized bytes
297+
char* cp = (char*)f;
298+
for (u32 i = 0; i < 4; i++) cp[size-1-i] = 0;
296299
return f;
297300
}
298301
#endif
@@ -315,8 +318,8 @@ fn u32 Lengths.add(Lengths** f_ptr, u32 count, const u8* lengths) {
315318
Lengths* f = *f_ptr;
316319

317320
u32 needed = f.count + count;
318-
if (needed > f.cap) {
319-
f = f.resize(needed);
321+
while (needed > f.cap) {
322+
f = f.resize(f.cap * 2);
320323
*f_ptr = f;
321324
}
322325

0 commit comments

Comments
 (0)