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

Scanf: %N returns unexpected value #3840

Closed
vicuna opened this issue Sep 29, 2002 · 2 comments
Closed

Scanf: %N returns unexpected value #3840

vicuna opened this issue Sep 29, 2002 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Sep 29, 2002

Original bug ID: 1413
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Gerd Stolpmann
Version: 3.06
OS: Linux
Submission from: p50816707.dip0.t-ipconnect.de (80.129.103.7)

Hello,

I have just tried the new Scanf module in 3.06, and discovered that the format
string
%N returns one more character than I would expect. For example:

sscanf "456" "%N" (fun x -> x)

returns 1, and not 0 ("the number of characters read so far", as stated in the
docs).

And

sscanf "" "%N" (fun x -> x)

raises the exception End_of_file.

I found this error because I needed a way to check that the whole buffer is
read, and
not just a prefix. So I thought that

sscanf iso_date_string 
       "%4d-%2d-%2d%N" 
       (fun year month day n -> 
         if n = String.length iso_date_string then
           (year,month,day)
         else
           Scanf.Scan_failure "Too many characters")

solved my problem, but it did not. Maybe it is a usuful extension to add a
notation
like $ in regexps that anchors at the end of strings.

Gerd

@vicuna
Copy link
Author

vicuna commented Oct 1, 2002

Comment author: administrator

Hello,

%N returns one more character than I would expect. For example:

sscanf "456" "%N" (fun x -> x)

returns 1, and not 0 ("the number of characters read so far", as stated in the docs).

And

sscanf "" "%N" (fun x -> x)

raises the exception End_of_file.

This is indeed a bug that no one here have noticed, even after careful
code review! (Not mentioning intensive testing on complex formats!)

Thank you very much for pointing it out.

I found this error because I needed a way to check that the whole buffer is
read, and
not just a prefix. So I thought that

sscanf iso_date_string 
       "%4d-%2d-%2d%N" 
       (fun year month day n -> 
         if n = String.length iso_date_string then
           (year,month,day)
         else
           Scanf.Scan_failure "Too many characters")

solved my problem, but it did not. Maybe it is a usuful extension to add a
notation like $ in regexps that anchors at the end of strings.

I am not completely sure that we need the $ extension.

The correction of those glitches is not completely trivial and I am
working on them. I will drop you a mail as soon as I have a
satisfactory correction.

Thank you again for reporting the bug.

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/

@vicuna
Copy link
Author

vicuna commented Jan 3, 2003

Comment author: administrator

fixed by PW at some unspecified date

@vicuna vicuna closed this as completed Jan 3, 2003
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant