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
Scanf cannot parse large unsigned int64s #6316
Comments
Comment author: @damiendoligez @gasche: shouldn't we postpone this one to 4.03? |
Comment author: @gasche Reasonable. I will postpone it so that it doesn't block the release, but if a patch comes in time, and is safe, I will be tempted to merge it in 4.02. |
Comment author: bvaugon I attatch two patches that fix the problem with two different solutions :
Any opinion? |
Comment author: @gasche The first patch is too invasive for 4.02, but could be an option for 4.03 (but it's not clear to me why we would write the unsigned parsing functions in OCaml, and keep the signed parsing in C). The second patch seems reasonable, I'd like the opinion of our release manager. |
Comment author: bvaugon In fact, since the OCaml implementation of int_of_string'like functions seems to be (between 1.5 and 2 times) faster than the current C implementation (on some machines, maybe not anywhere), it might be interresting (also for portability, homogeneity and simplicity) to encode all of them in OCaml. The first version principally adds code, and contains modifications of only few lines of the existing ml code. IMHO, it seems safer to release it than the second version that modify the existing C code, except if the syntax "0u..." is considered interesting for int_of_string. I forgot to tell that this patch also fix "%u", "%lu" and "%nu". |
Comment author: @xavierleroy Fixed in commit 16241. I came up independently with the second approach suggested by bvaugon, so it must be the right approach :-) I didn't feel the need to reject int_of_string "-0u123", because we already have a tolerance for int_of_string "-0x123". |
Original bug ID: 6316
Reporter: seliopou
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2017-02-16T14:15:06Z)
Resolution: fixed
Priority: normal
Severity: minor
Platform: OCaml 4.01.0
OS: Debian
OS Version: wheezy/sid
Version: 4.01.0
Target version: 4.03.0+dev / +beta1
Fixed in version: 4.03.0+dev / +beta1
Category: standard library
Tags: junior_job
Monitored by: @hcarty
Bug description
Any string literal representing an unsigned int64 that is larger than 2^63 cannot be parsed by Scanf.sscanf using the format string "%Lu".
Steps to reproduce
The following code snippet consistently reproduces the issue:
Scanf.sscanf "12306459064359371967" "%Lu" (fun i -> i);;
File attachments
The text was updated successfully, but these errors were encountered: