You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a piece of code that processes smaller sequential slices of a larger slice. Rather than getting a slice of length zero at the end, I get a segmentation fault.
conststd=@import("std");
constCHUNK_LEN=2;
fnslice_to_zero(input: []constu8) void {
while (input.len>0) {
consttake=std.math.min(input.len, CHUNK_LEN);
_=input[0..take]; // Imagine this slice chunk is used for somethinginput=input[take..];
}
}
test"slicing down to zero length" {
slice_to_zero("");
slice_to_zero("foo");
}
The text was updated successfully, but these errors were encountered:
This is illegal as parameters are const by default => #4015
_=input[0..take];
This is a long-standing issue that affects many builtins (and also the slice operator), when the destionation is _ the codegen gets a nullptr for the result_loc and so it segfaults. I'm pretty sure there are a few tickets open about that.
It looks like my code works if I create a new slice variable from the const slice parameter. Lack of compiler error was allowing me to footgun. Thanks.
andrewrk
added
bug
Observed behavior contradicts documented or intended behavior
stage1
The process of building from source via WebAssembly and the C backend.
labels
Feb 1, 2020
Possibly related to #788.
I have a piece of code that processes smaller sequential slices of a larger slice. Rather than getting a slice of length zero at the end, I get a segmentation fault.
The text was updated successfully, but these errors were encountered: