hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit b5c269e97ba07b784c94b460da9e07a7d7374186
parent 64d200943c131a916ff7ee08c28725151b53b0d0
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Thu,  6 May 2021 13:33:47 -0400

Fix implicit casts from *void to nullable pointers

These were mistakenly allowed due to a harec bug

Signed-off-by: Eyal Sawady <ecs@d2evs.net>

Diffstat:
Mnet/unix/+linux.ha | 6++++--
Mrt/malloc.ha | 4++--
Mstrings/cstrings.ha | 5++++-
3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/net/unix/+linux.ha b/net/unix/+linux.ha @@ -13,8 +13,10 @@ export fn to_native(addr: addr) (rt::sockaddr | invalid) = { ... } }; - rt::memcpy(&ret.un.sun_path, - (&addr: *types::string).data, len(addr)); + match ((&addr: *types::string).data) { + null => void, + data: *[*]u8 => rt::memcpy(&ret.un.sun_path, data, len(addr)), + }; ret.un.sun_path[len(addr)] = 0; return ret; }; diff --git a/rt/malloc.ha b/rt/malloc.ha @@ -124,8 +124,8 @@ fn free_large(_p: *void, s: size) void = { fn free_small(p: *void, s: size) void = { let b = size2bin(s); let q = bins[b]; - *(p: **void) = q; - bins[b] = p: nullable *void; + *(p: *nullable *void) = q; + bins[b] = p; }; // Changes the allocation size of a pointer to n bytes. If n is smaller than diff --git a/strings/cstrings.ha b/strings/cstrings.ha @@ -45,7 +45,10 @@ export fn to_c(s: const str) *char = { null => abort("Out of memory"), p: *[*]u8 => p, }; - rt::memcpy(ptr, (&s: *types::string).data, len(s)); + match ((&s: *types::string).data) { + null => void, + data: *[*]u8 => rt::memcpy(ptr, data, len(s)), + }; ptr[len(s)] = 0; return ptr: *char; };