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
The &"foo"[0..] expression is taking the address of an rvalue. However, when it is modified in the popFirstElement function this segfault occurs:
1/1 test "bug"...Segmentation fault at address 0x201578
/home/marler8997/git/zog/bug.zig:2:30: 0x205723 in popFirstElement (test)
stringRef.* = stringRef.*[1..];
^
/home/marler8997/git/zog/bug.zig:6:20: 0x205592 in test "bug" (test)
popFirstElement(&"foo"[0..]);
^
/home/marler8997/bin/zig-linux-x86_64-0.5.0+8b459216/lib/zig/std/special/test_runner.zig:13:25: 0x2284e1 in std.special.main (test)
if (test_fn.func()) |_| {
^
/home/marler8997/bin/zig-linux-x86_64-0.5.0+8b459216/lib/zig/std/special/start.zig:204:37: 0x227355 in std.special.posixCallMainAndExit (test)
const result = root.main() catch |err| {
^
/home/marler8997/bin/zig-linux-x86_64-0.5.0+8b459216/lib/zig/std/special/start.zig:102:5: 0x2271cf in std.special._start (test)
@noInlineCall(posixCallMainAndExit);
^
Tests failed. Use the following command to reproduce the failure:
/home/marler8997/git/zog/zig-cache/o/lNWDEb7CbHCUpRDUVTsn8ZiwsvJwp9_hF8wwgR91Xl4TNulOrqSQPw1Tzn-dT9B_/test
I'm not sure how rvalue references work in Zig, but I'm guessing that they are supposed to be const. In this case this would mean that the expression &"foo"[0..] should become type *const []const u8 rather than *[]const u8. If this was the case, then this would have been a compile error because you wouldn't be able to pass a const reference to the popFirstElement function.
The text was updated successfully, but these errors were encountered:
marler8997
changed the title
Address of RValue isn't const and causes segfault when modified
Modifying address of string literal as an rvalue-reference causes segfault when modified
Oct 13, 2019
marler8997
changed the title
Modifying address of string literal as an rvalue-reference causes segfault when modified
Modifying an rvalue reference of a string literal causes segfault
Oct 13, 2019
Take the following example:
The
&"foo"[0..]
expression is taking the address of an rvalue. However, when it is modified in thepopFirstElement
function this segfault occurs:I'm not sure how rvalue references work in Zig, but I'm guessing that they are supposed to be const. In this case this would mean that the expression
&"foo"[0..]
should become type*const []const u8
rather than*[]const u8
. If this was the case, then this would have been a compile error because you wouldn't be able to pass a const reference to thepopFirstElement
function.The text was updated successfully, but these errors were encountered: