Re:Parsing can become accidentally quadratic because of sscanf
by froh on Thursday March 04, 2021 @11:06PM
(#26352549)
fmemopen is meanwhile portable and part of posix.
https://pubs.opengroup.org/onlinepubs/9699919799/functions/f...
A mechanism for turning a string in memory into a string should not be taking its length.
GBLIC has an extension called fmemopen. The API is:
This interface smells like it might have the flaw that if someone wants "buf" to come from a null-terminated string, they must measure that string in order to supply the size parameter.I.e. the underlying mechanism is binary, and does not stop at null characters.
There needs to be a separate mechanism with a different underlying stream implementation:
This doesn't require a size.That fmemopen extension points to a solution to the original problem, though non-portable: open the entire buffer of numbers as a stream in one fmemopen call, and then use fscanf to march through it.