Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should json_object_array_get_idx check whether input obj is array? #280

Closed
sigusr1 opened this issue Oct 28, 2016 · 2 comments
Closed

Should json_object_array_get_idx check whether input obj is array? #280

sigusr1 opened this issue Oct 28, 2016 · 2 comments

Comments

@sigusr1
Copy link

sigusr1 commented Oct 28, 2016

If input param obj isn't array, json_object_array_get_idx encounter segment fault.

@hawicz
Copy link
Member

hawicz commented Oct 28, 2016

What would it do when passed another object type? It seems like a pretty significant programmer error to be trying to get an array element out of something that isnt an array, so perhaps it could emit a more useful error to stderr, then reliably crash by calling abort.

@ploxiln
Copy link
Contributor

ploxiln commented Oct 28, 2016

This is a case where an assert() may be appropriate, something like

assert(json_object_get_type(jso) == json_type_array);

(when compiled with NDEBUG it goes away, which is appropriate for purely-programmer-error)

hawicz added a commit that referenced this issue Oct 29, 2016
@hawicz hawicz closed this as completed Oct 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants