[PATCH] db: Add more tests for retrieving subscribers from a DB and avoid NULL dereference when something goes wrong in tests.

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Alexander Chemeris alexander.chemeris at gmail.com
Sun Oct 6 12:34:59 UTC 2013


On Sun, Oct 6, 2013 at 1:41 PM, Holger Hans Peter Freyther
<holger at freyther.de> wrote:
> On Sat, Oct 05, 2013 at 12:16:07PM +0200, Alexander Chemeris wrote:
>>  #define SUBSCR_PUT(sub) \
>> -     sub->net = &dummy_net;  \
>> -     subscr_put(sub);
>> +     if (sub) { \
>> +             sub->net = &dummy_net;  \
>> +             subscr_put(sub); \
>> +     }
>
> I don't like this semantic change. Either the tests expects a valid
> subscriber or it doesn't. It is not a "maybe" this query will result
> in a look up.

My changes are to avoid _segfault_ when something goes wrong. Test
will still fail, because it will print info about NULL original or
copy, and comparison with the proper output will fail.

I decided to do it that way, because it makes the code of the test
itself looking clean. Otherwise we have to put this "if(sub)" to every
test, which looks ugly. But if you prefer some other way - please go
ahead, I don't really care about this. I just tried to keep the clean
look.

-- 
Regards,
Alexander Chemeris.
CEO, Fairwaves LLC / ООО УмРадио
http://fairwaves.ru




More information about the OpenBSC mailing list