Skip to content

Commit c901870

Browse files
committed
Zero-fill pkguiAlloc()'s output.
1 parent d8200a9 commit c901870

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

pkgui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define pkguiHFileIncluded
44

55
#include <stdlib.h>
6+
#include <string.h>
67
#include <time.h>
78
#include "ui.h"
89

util.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import "C"
1212
//export pkguiAlloc
1313
func pkguiAlloc(n C.size_t) unsafe.Pointer {
1414
// cgo turns C.malloc() into a panic-on-OOM version; use it
15-
// TODO make sure it zero-initializes too
16-
return C.malloc(n)
15+
ret := C.malloc(n)
16+
// and this won't zero-initialize; do it ourselves
17+
C.memset(ret, 0, n)
18+
return ret
1719
}
1820

1921
func freestr(str *C.char) {

0 commit comments

Comments
 (0)