On 2017-11-03 21:32, Alberto Garcia wrote:
> On Fri 03 Nov 2017 09:22:39 PM CET, Alberto Garcia wrote:
>>>> -        assert(offset);
>>>
>>> I don't think this assert() was meant as a protection against offset
>>> being 0. :-)
>>
>> After the new check offset is now guaranteed to be 0, so what's the
>> point of keeping the assert() ?
> 
> I meant "guaranteed _not_ to be 0" :-)

That is the point of an assert.

An assert should not guard against something that can occur.  It should
express that something will always be true (in this case that the offset
is guaranteed not to be 0).  Then, someone who reads the code does not
have to read all code paths to check whether that condition is true.

If an assert checks a condition that can be true, it's wrong.  Then
either the code is buggy (like it was before this patch) or the error
should be handled gracefully instead of aborting the program.

In a perfect world, all assert()s would be checked at compile time.

Max

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to