OSDN Git Service

gpt: eliminate four PED_ASSERT uses
authorJim Meyering <meyering@redhat.com>
Fri, 30 Dec 2011 20:03:06 +0000 (21:03 +0100)
committerJim Meyering <meyering@redhat.com>
Mon, 9 Jan 2012 11:01:43 +0000 (12:01 +0100)
* libparted/labels/gpt.c (_parse_header): Convert a few PED_ASSERT
uses to friendlier 'test-and-return-0's. Reported by Graham Markall
in http://thread.gmane.org/gmane.comp.gnu.parted.bugs/10653

libparted/labels/gpt.c

index 9d464c6..b812c4a 100644 (file)
@@ -728,19 +728,18 @@ _parse_header (PedDisk *disk, const GuidPartitionTableHeader_t *gpt,
     GPT_DEFAULT_PARTITION_ENTRY_ARRAY_SIZE / disk->dev->sector_size;
 
   if (last_usable_if_grown > last_usable_min_default)
-    {
-      last_usable_if_grown = last_usable_min_default;
-    }
+    last_usable_if_grown = last_usable_min_default;
 
-  PED_ASSERT (last_usable > first_usable);
-  PED_ASSERT (last_usable <= disk->dev->length);
+  if (last_usable <= first_usable
+      || disk->dev->length < last_usable)
+    return 0;
 
-  PED_ASSERT (last_usable_if_grown > first_usable);
-  PED_ASSERT (last_usable_if_grown <= disk->dev->length);
+  if (last_usable_if_grown <= first_usable
+      || disk->dev->length < last_usable_if_grown)
+    return 0;
 
   if (!asked_already && last_usable < last_usable_if_grown)
     {
-
       PedExceptionOption q;
 
       q = ped_exception_throw