From: Denis Efremov
> Sent: 01 October 2019 16:13
...
> Just found an official documentation to this issue:
> https://gcc.gnu.org/gcc-4.9/porting_to.html
> "Null pointer checks may be optimized away more aggressively
> ...
> The pointers passed to memmove (and similar functions in <string.h>) must be 
> non-null
> even when nbytes==0, so GCC can use that information to remove the check 
> after the
> memmove call. Calling copy(p, NULL, 0) can therefore deference a null pointer 
> and crash."

Right, so just don't code a NULL pointer test after a memcpy() call.
There is no need to avoid the call itself.

> But again, I would say that the bug in this code is because the if condition 
> was copy-pasted
> and it should be inverted.

Oh, the code is question is just stupidly bad.
It seemed to do:
        if (a)
                x;
        else if (!a)
                y;
        else
                error ("all borked")

If the whole driver is written like that it needs fixing before anyone takes a 
serious look at it.

        David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, 
UK
Registration No: 1397386 (Wales)
_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to