News for hackers. Stuff that matters.
Re:Parsing can become accidentally quadratic because of sscanf by kazinator on Tuesday March 02, 2021 @12:58PM (#26318172)
My thoughts on that is that the problem is at a level below sscanf; in other words, what else is affected?

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:

  FILE *fmemopen(void *buf, size_t size, const char *mode);
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:

  FILE *fstropen(const char *str); // mode implied: "r"
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.

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...