Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#38 at() and at_nocase() should fail fast

open-wont-fix
nobody
None
5
2012-05-30
2012-05-30
Anonymous
No

In JSONNode::at() and friends, if JSON_SAFE is off, the compiler will detect and warn that the function does not return anything at the end (since it doesn't throw without _SAFE defined).

I understand this is done for speed, but it should at least do something.

Options:
* exit(1) but you may not want your unit tests or production code failing like that.
* return *this ... it is returning the wrong node, but at least its returning something. The library user should either use exceptions or define JSON_FAIL, and check that before using the returned value.
* Define a special static "error" JSONNode that can be returned in such situations. I suppose it could be put in protected memory so if the library user tries to do anything with the node, then the OS will detect the problem.
* Create a new blank node and return that. Memory leaks could be a problem if reference counting doesn't work in this case.

Thoughts?
thanks,
Paul

Discussion


  • Anonymous
    2012-05-30

    Sorry, I meant to say: this problem springs up when JSON_SAFE and JSON_NO_EXCEPTIONS is undefined.

     

  • Anonymous
    2012-05-30

    Argh.
    when:
    JSON_SAFE is undefined
    JSON_NO_EXCEPTIONS is defined.

     
  • The behavior of the at() function is the same as it is in STL by design. If exceptions are not allowed, the behavior is undefined.

     
    • status: open --> open-wont-fix