r21598

Geert Janssens janssens-geert at telenet.be
Sat Oct 29 11:43:08 EDT 2011


On zaterdag 29 oktober 2011, you wrote:
> Sorry to bother you, but did I miss some thing, I could not get it to fail
> on my testing.
> 
> Are these changes as of failure for you or are these just in case, should I
> being looking to do the same in future similar cases.
> 
> Regards,
> 
>      Robert

I did indeed experience a crash on the strcmp on filter[1]. I didn't run into 
it when I tested your patch the first time, but when I loaded a test file that 
already contained a filter kvp from your first patch (which didn't take the 
dates into account) it crashed.

In that scenario, the g_str_split returns only filter[0], sets filter[1] to 
NULL and filter[2] is out of bounds. I chose to be careful and check on null 
for all the other instances of strcmp as well.

It is very unlikely that anybody else will ever be in this same situation: try 
to open a data file containing a kvp written with your "version 1" filter code 
in gnucash with the "version 2" filter code, but it never hurts to pro-
actively avoid a potential  crash altogether.

strcmp is not NULL-safe, so I would advise to always explicitly check for non-
NULL on its operands, or use the g_strcmp0 alternative instead.

In this particular case, I chose to keep strcmp, but the explicit check was 
still partly needed.

I hope this explains why I did what I did.

Geert


More information about the gnucash-devel mailing list