Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Const pointer with large array size doesn't throw any compiler error #19952

Open
fmamud opened this issue May 12, 2024 · 0 comments
Open

Const pointer with large array size doesn't throw any compiler error #19952

fmamud opened this issue May 12, 2024 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@fmamud
Copy link

fmamud commented May 12, 2024

Zig Version

0.12.0

Steps to Reproduce and Observed Behavior

I was testing the code snippet bellow and I was expecting a compiler error, but it doesn't happened.

const t: *const [1000]u8 = "asdf";
std.debug.print("string: {s}\n", .{t});

My current targeting is arm64:

$ sw_vers
ProductName:		macOS
ProductVersion:		14.4.1
BuildVersion:		23E224

I do see different kind of overflow data depending on release mode. Please see few examples:

Build 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

Expected Behavior

A compiler error, like before on slightly older version 0.12.0-dev.3518+d2be725e4.

test.zig:10:29: error: expected type '*const [1000]u8', found '*const [4:0]u8'
 const t: *const [1000]u8 = "asdf";
                            ^~~~~~
@fmamud fmamud added the bug Observed behavior contradicts documented or intended behavior label May 12, 2024
@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label May 13, 2024
@Vexu Vexu added this to the 0.13.0 milestone May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

2 participants