[CLN-list] Integer parser

Richard B. Kreckel kreckel at in.terlu.de
Mon May 1 22:21:01 CEST 2017


Hi,

On 04/27/2017 02:56 PM, Thomas Luthe wrote:
> I am writing my own parser for expressions and want to use cln for
> parsing integers within these expressions, specifically using
> 
> read_integer (const cl_read_flags& flags, const char * string, const
> char * string_limit, const char * * end_of_parse) .
> 
> Unfortunately this fails with a cln::read_number_bad_syntax_exception if
> the integer immediately precedes a "/" (example attached). I have traced
> the cause back to line 119 in cl_I_read.cc. My suspicion is that the
> check for "/" originates from the rational case (as the file states that
> the code is a condensed version of read_rational()) and could simply be
> removed, but I am not familiar enough with the code to be certain this
> would not break other use cases.
> 
> Even though I can work around this by to determining the end of the
> integer before the call and setting string_limit accordingly, I would
> appreciate a fix for this issue.

You're attempting to read string "1/2" into an cl_I, but you don't tell
the read_integer function where the integer ends. In this case, the "the
string in memory must contain exactly one number and nothing more, else
an exception will be thrown" (quoted from section 5.2 of the manual).

You really should do some basic string parsing before passing strings to
the CLN input function.

All my best,
  -richy.
-- 
Richard B. Kreckel
<https://in.terlu.de/~kreckel/>


More information about the CLN-list mailing list