February 2020 Archives

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:


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:


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


About Ben Bullock

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