3 ms·
It's hard for a library to portably know when the C stack will exhaust or give a concrete estimate that makes sense for documentation purposes. Firstly, that c
by asveikau 7y ago
It's hard for a library to portably know when the C stack will exhaust or give a concrete estimate that makes sense for documentation purposes.
Firstly, that concept is not exposed at all to standard complaint C code. The standard is vague enough to allow for many possible variations of the program stack abstraction. So you would not be portable, standard C.
Second, the library author doesn't know ahead of time how much stack space you, the caller, have consumed before calling the library. Do you call it deep inside some ui framework with a big stack? With a huge i/o buffer on the stack? They don't know.
Translating all of this into "this is how deeply nested your json can be" is not a sane exercise, at best you can give a machine-specific guess that will vary a bit with your own application's stack needs.
But perhaps one can side-step all of that and get most of the way with an artificial, arbitrary-constant runtime depth check that is safely below likely actual stack limits.
- ken 7y agoSure, that’s all true. So don’t use the C stack for parsing. It’s not difficult.