diff options
Diffstat (limited to 'vendor/modernc.org/libc/memgrind_musl.go')
| -rw-r--r-- | vendor/modernc.org/libc/memgrind_musl.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/vendor/modernc.org/libc/memgrind_musl.go b/vendor/modernc.org/libc/memgrind_musl.go index 1dc25ef2f..ee7c2dcf0 100644 --- a/vendor/modernc.org/libc/memgrind_musl.go +++ b/vendor/modernc.org/libc/memgrind_musl.go @@ -77,7 +77,9 @@ func Xmalloc(t *TLS, size Tsize_t) uintptr { trc("t=%v size=%v, (%v:)", t, size, origin(2)) } if size == 0 { - return 0 + // malloc(0) should return unique pointers + // (often expected and gnulib replaces malloc if malloc(0) returns 0) + size = 1 } allocatorMu.Lock() @@ -113,18 +115,18 @@ func Xmalloc(t *TLS, size Tsize_t) uintptr { // void *calloc(size_t nmemb, size_t size); func Xcalloc(t *TLS, n, size Tsize_t) uintptr { if __ccgo_strace { - trc("t=%v size=%v, (%v:)", t, size, origin(2)) + trc("t=%v n=%v size=%v, (%v:)", t, n, size, origin(2)) } rq := int(n * size) if rq == 0 { - return 0 + rq = 1 } allocatorMu.Lock() defer allocatorMu.Unlock() - p, err := allocator.UintptrCalloc(int(n * size)) + p, err := allocator.UintptrCalloc(rq) // if dmesgs { // dmesg("%v: %v -> %#x, %v", origin(1), n*size, p, err) // } |
