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

Cstring does not check for null-termination #16499

Closed
Ismael-VC opened this issue May 21, 2016 · 0 comments
Closed

Cstring does not check for null-termination #16499

Ismael-VC opened this issue May 21, 2016 · 0 comments
Labels
strings "Strings!"

Comments

@Ismael-VC
Copy link
Contributor

This is pasted verbatim from @ScottPJones report at julia-dev:


In the course of adding support to CSV.jl for being able to load into arbitrary AbstractFloat types, via a keyword argument floattype (which defaults to Float64),
I ran into a number of bugs (both in v0.4.x and v0.5-dev). The problem occurs because pointer_to_string() does not create a string that has a terminating \0 (which I feel is correct),
but Cstring does not ensure that a string passed to C has a terminating \0.
This is inconsistent with Cwstring, which does make sure that a Cwstring does have a terminating Cwchar(0).

I'd make a PR to fix these bugs, but since I'm unable to, I'm posting the issue here.

Here are some test cases demonstrating the bugs:

julia> s = "53.9abcdef"
"53.9abcdef"

julia> u = pointer_to_string(pointer(s.data),2)
"53"

julia> t = pointer_to_string(pointer(s.data),4)
"53.9"

julia> parse(Dec64, t)
ERROR: ArgumentError: invalid number format 53.9
 in parse at /j/DecFP.jl/src/DecFP.jl:82

julia> parse(Dec64, u)
ERROR: ArgumentError: invalid number format 53
 in parse at /j/DecFP.jl/src/DecFP.jl:82

julia> parse(BigInt, u)
ERROR: ArgumentError: invalid BigInt: "53"
 in tryparse_internal at gmp.jl:104
 in parse at parse.jl:146

julia> parse(BigFloat, t)
ERROR: ArgumentError: invalid number format "53.9" for BigFloat
 in parse at parse.jl:164
@simonbyrne simonbyrne added the strings "Strings!" label May 22, 2016
@StefanKarpinski StefanKarpinski mentioned this issue Jun 2, 2016
32 tasks
simonbyrne added a commit that referenced this issue Jun 2, 2016
Should fix #16499. Two things I'm not sure about:
1. whether it is okay to use `unsafe_load` in this manner?
2. is this the appropriate place to call `String`, or should it be done in `cconvert`?
simonbyrne added a commit that referenced this issue Jun 2, 2016
Should fix #16499. Two things I'm not sure about:
1. whether it is okay to use `unsafe_load` in this manner?
2. is this the appropriate place to call `String`, or should it be done in `cconvert`?
@simonbyrne simonbyrne changed the title Bugs parsing BigInt/Float &Decimals when no \0 immediately past end Cstring does not check for null-termination Jun 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
strings "Strings!"
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants