[parted-devel] [PATCH] Handle ped_disk_get_last_partition_num(disk) == -1 gracefully

Jim Meyering jim at meyering.net
Wed Aug 6 17:37:04 UTC 2008


Soren Hansen <soren at canonical.com> wrote:

> If ped_disk_get_last_partition_num(disk) fails (which it will if disk is
> a loopback device), it will return -1. This in turn will cause
> _disk_sync_part_table and  _dm_reread_part_table to attempt to malloc a
> sizeof(int)*-1, which instantly causes a "Fatal: Out of memory".
>
> This patch detects this case, and pretends the last partition id is 0.

Thanks, but I prefer to keep declaration and first use together,
when reasonable.

How about this instead?  (parted assumes c99 already)
When that largest partition number is <= 0,
there's no point in allocating memory (even just a byte).



More information about the parted-devel mailing list