commit ce546b01ca8a96984661cebd616d87662cb389dc
parent 28ed6fce2c9ab720aa4a35d07a114dcdcf9f3de3
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date: Wed, 2 Mar 2022 01:35:10 +0100
strings::dup: don't overallocate and don't read out of bouds
a remnant of the time we had C strings
Signed-off-by: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Diffstat:
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/strings/dup.ha b/strings/dup.ha
@@ -14,8 +14,7 @@ export fn dup(s: const str) str = {
case let b: *[*]u8 =>
yield b;
};
- let buf: []u8 = alloc([0...], in.length + 1);
- buf[..in.length + 1z] = id[..in.length + 1];
+ let buf: []u8 = alloc(id[..in.length], in.length);
let out = types::string {
data = buf: *[*]u8,
length = in.length,