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

String constructor can segfault #16470

Closed
vtjnash opened this issue May 20, 2016 · 4 comments · Fixed by #16731
Closed

String constructor can segfault #16470

vtjnash opened this issue May 20, 2016 · 4 comments · Fixed by #16731
Labels
regression Regression in behavior compared to a previous version

Comments

@vtjnash
Copy link
Member

vtjnash commented May 20, 2016

julia> String(convert(Ptr{UInt8}, 1))
Segmentation fault: 11

expected result: MethodError, "Ptr{UInt8}(1)", anything but crashing?

Julia constructors shouldn't segfault, only methods that can should have unsafe_ in the name

@vtjnash vtjnash added the regression Regression in behavior compared to a previous version label May 20, 2016
@nalimilan
Copy link
Member

Cf. discussion following #16107 (comment). I also think methods playing with pointers should all be marked unsafe_*, but @stevengj has a different opinion.

@StefanKarpinski
Copy link
Member

I don't really have a strong opinion here so whenever you guys decide what we should call this, I'll change it. If this is going to go out of the String constructor, then it should be part of the same function as pointer_to_string, which is a terrible name and also doesn't start with unsafe_.

@stevengj
Copy link
Member

stevengj commented May 20, 2016

(If we rename pointer_to_string, we should also rename pointer_to_array.)

Maybe just unsafe_string(ptr, [len]) for the copying constructor (analogous to the old bytestring(ptr, len) function). It should be short, since this is used all over the place.

@nalimilan
Copy link
Member

We could also have a more generic API, which would allow extensions for custom string types. Something like unsafe_constructor(String, ptr, [len]) and unsafe_constructor(Array, ptr, dims).

@StefanKarpinski StefanKarpinski mentioned this issue Jun 2, 2016
32 tasks
stevengj added a commit to stevengj/julia that referenced this issue Jun 3, 2016
…unsafe_string_wrapper, and unsafe_array_wrapper; restore non-copying behavior of String(::Vector{UInt8}) constructor (closes JuliaLang#16470, closes JuliaLang#16713)
stevengj added a commit to stevengj/julia that referenced this issue Jun 4, 2016
…unsafe_string_wrapper, and unsafe_array_wrapper; restore non-copying behavior of String(::Vector{UInt8}) constructor (closes JuliaLang#16470, closes JuliaLang#16713)
stevengj added a commit to stevengj/julia that referenced this issue Jun 8, 2016
…unsafe_string_wrapper, and unsafe_array_wrapper; restore non-copying behavior of String(::Vector{UInt8}) constructor (closes JuliaLang#16470, closes JuliaLang#16713)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression Regression in behavior compared to a previous version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants