[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [Qemu-block] [PATCH v2 3/7] qcow2: Prevent allocating c
From: |
Max Reitz |
Subject: |
Re: [Qemu-devel] [Qemu-block] [PATCH v2 3/7] qcow2: Prevent allocating compressed clusters at offset 0 |
Date: |
Mon, 6 Nov 2017 13:36:01 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 |
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
signature.asc
Description: OpenPGP digital signature
[Qemu-devel] [PATCH v2 1/7] qcow2: Prevent allocating refcount blocks at offset 0, Alberto Garcia, 2017/11/03
[Qemu-devel] [PATCH v2 7/7] qcow2: Assert that the crypto header does not overlap other metadata, Alberto Garcia, 2017/11/03
[Qemu-devel] [PATCH v2 2/7] qcow2: Prevent allocating L2 tables at offset 0, Alberto Garcia, 2017/11/03
[Qemu-devel] [PATCH v2 6/7] qcow2: Add iotest for an empty refcount table, Alberto Garcia, 2017/11/03
[Qemu-devel] [PATCH v2 5/7] qcow2: Add iotest for an image with header.refcount_table_offset == 0, Alberto Garcia, 2017/11/03
[Qemu-devel] [PATCH v2 4/7] qcow2: Don't open images with header.refcount_table_clusters == 0, Alberto Garcia, 2017/11/03