-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
openArray on empty seq triggers UB: member access within null pointer #20294
Comments
Not orc specific happens with the default GC as well. |
This works: import hashes
template makeOpenArray(x: seq): untyped =
if x.len > 0: toOpenArray(x, 0, x.len-1)
else: toOpenArray(cast[ptr UncheckedArray[typeof(x[0])]](nil), 0, -1)
proc main =
var x: seq[byte]# = @[1, 2, 3]
block:
echo hash(x.makeOpenArray)
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What happened?
This bug is observed a lot in the stdlib where
openArray
is used instead ofseq
such as in==
orhash
.This is caused because of this code being generated:
Nim Version
Nim Compiler Version 1.7.1 [Linux: amd64]
Compiled at 2022-08-31
Copyright (c) 2006-2022 by Andreas Rumpf
git hash: 5211a47
active boot switches: -d:release --gc:markAndSweep
Current Standard Output Logs
Expected Standard Output Logs
Possible Solution
cstring(x) converter handles empty strings correctly.
Additional Information
Build command:
The text was updated successfully, but these errors were encountered: