av_fetch can return NULL

If you create an array by inserting values, in the following way,

$thing{key}[10] = 1;

and then don't populate the rest of the array, a call to av_fetch in the array to retrieve values lower than the tenth one may return a NULL value.

I found this out the hard way, by segmentation faults returned from the following dereference:

https://metacpan.org/source/BKB/JSON-Create-0.24/json-create-perl.c#L1021

The important thing to do here is not to rely on av_fetch to not return nulls. I fixed the problem in JSON::Create version 0.25:

https://metacpan.org/source/BKB/JSON-Create-0.25/json-create-perl.c#L1036

I chose to populate the output JSON with the JSON value "null" if there a NULL value is returned by av_fetch:

https://metacpan.org/source/BKB/JSON-Create-0.25/json-create-perl.c#L1044

Leave a comment

About Ben Bullock

user-pic Perl user since about 2006, I have also released some CPAN modules.