mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
fix out-of-bounds write
This commit is contained in:
parent
898a140f64
commit
1070b5c4b2
1 changed files with 6 additions and 4 deletions
|
@ -32,19 +32,21 @@ const RocStr = struct {
|
||||||
var index : u8 = 0;
|
var index : u8 = 0;
|
||||||
// Zero out the data, just to be safe
|
// Zero out the data, just to be safe
|
||||||
while (index < rocStrSize) {
|
while (index < rocStrSize) {
|
||||||
var offset_ptr = @intToPtr(*usize, target_ptr + index);
|
var offset_ptr = @intToPtr(*u8, target_ptr + index);
|
||||||
offset_ptr.* = 0;
|
offset_ptr.* = 0;
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = 0;
|
index = 0;
|
||||||
while (index < len) {
|
while (index < len) {
|
||||||
var offset_ptr = @intToPtr(*usize, target_ptr + index);
|
var offset_ptr = @intToPtr(*u8, target_ptr + index);
|
||||||
offset_ptr.* = bytes[index];
|
offset_ptr.* = bytes[index];
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
const final_byte_ptr = @intToPtr(*usize, target_ptr + rocStrSize - 1);
|
|
||||||
final_byte_ptr.* = len ^ 0b10000000;
|
// set the final byte to be the length
|
||||||
|
const final_byte_ptr = @intToPtr(*u8, target_ptr + rocStrSize - 1);
|
||||||
|
final_byte_ptr.* = @truncate(u8, len) ^ 0b10000000;
|
||||||
|
|
||||||
return ret_small_str;
|
return ret_small_str;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue