Hey, please could you help me to understand what is the expected behaviour of code snippet bellow?
const t: *const [1000]u8 = "asdf";
std.debug.print("string: {s}\n", .{t});
I’m using a scaffold build file from zig init
, and using zig build && ./zig-out/bin/main
to test it.
Compilation is fine with no errors. Should I get a panic instead or it’s expected?
I do see different kind of overflow data depends on release mode. Please see few examples:
Buil type cmd | Output |
---|---|
zig build |
string: asdfinteger overflowattempt to cast negative value to unsigned integerh�Fstring: {s} invalid error codethread {} panic: {s} Panicked during a panic. Aborting. (msg truncated)@memcpy arguments aliasswitch on corrupt valueunable to install segfault handler, maybe adjust have_segfault_handling_support in std/debug.zigreached unreachable codeDeadlock detectedincorrect alignment’noreturn’ function returnedattempt to use null valueinteger cast truncated bitscast causes pointer to be null__TEXT__unwind_info__eh_frame{s}:{d}:{d}???:?:?: 0x{x} in {s} ({s}) ^???for loop over objects with non-equal lengths@memcpy arguments have non-equal lengths__DWARF__debug_info__debug_abbrev__debug_str__debug_str_offsets__debug_line__debug_line_str__debug_ranges__debug_loclists__debug_rnglists__debug_addr__debug_names__debug_frame__eh_frame_h |
zig build --release=small |
string: asdf00010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899OperationNotSupported 8888@��0 ��04X���� t |
zig build --release=fast |
string: asdf(msg truncated)failed to set noop SIGPIPE handler: {s}00010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899OperationNotSupportedDiskQuotaFileTooBigInputOutputNoSpaceLeftDeviceBusyInvalidArgumentAccessDeniedBrokenPipeSystemResourcesOperationAbortedNotOpenForWritingLockViolationWouldBlockConnectionResetByPeerUnexpectedOverflowInvalidUtf8Utf8ExpectedContinuationUtf8OverlongEncodingUtf8EncodesSurrogateHalfUtf8CodepointTooLargeUtf8InvalidStartByteTruncatedInputUtf8CannotEncodeSurrogateHalfCodepointTooLargeMissingDebugInfoUnsupportedOperatingSystemInvalidDebugInfoOutOfMemorySharingViolationPathAlreadyExistsFileNotFoundPipeBusyNameTooLongInvalidWtf8BadPathNameNetworkNotFoundAntivirusInterferenceSymLinkLoopProcessFdQuotaExceededSystemFdQuotaExceededNoDeviceIsDirNotDirFileLocksNotSupportedFileBusy |
zig build --release=safe |
string: asdf__TEXT__unwind_info__eh_frame__DWARF__debug_info__debug_abbrev__debug_str__debug_str_offsets__debug_line__debug_line_str__debug_ranges__debug_loclists__debug_rnglists__debug_addr__debug_names__debug_frame__eh_frame_hdr(msg truncated)failed to set noop SIGPIPE handler: {s}00010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899OperationNotSupportedDiskQuotaFileTooBigInputOutputNoSpaceLeftDeviceBusyInvalidArgumentAccessDeniedBrokenPipeSystemResourcesOperationAbortedNotOpenForWritingLockViolationWouldBlockConnectionResetByPeerUnexpectedMissingDebugInfoUnsupportedOperatingSystemInvalidDebugInfoOutOfMemorySharingViolationPathAlreadyExistsFileNotFoundPipeBusyNameTooLongInvalidUtf8InvalidWtf8BadPathNameNetworkNotFoundAntivirusInterferenceSymLinkLoopProcessFdQuotaExc |
Many thanks in advance.
Best,
Felipe