[Parted-commits] GNU Parted Official Repository: Changes to 'master'

Jim Meyering meyering at alioth.debian.org
Fri Feb 3 15:44:51 UTC 2012


 include/parted/parted.in.h            |    1 
 libparted/libparted.c                 |   15 -----
 parted/parted.c                       |  100 +++++++++++++---------------------
 scripts/data/abi/baseline_symbols.txt |    1 
 tests/t0209-gpt-pmbr_boot.sh          |    2 
 5 files changed, 42 insertions(+), 77 deletions(-)

New commits:
commit f418609c79e97bffe41bb361cc6d07806c902e7f
Author: Jim Meyering <meyering at redhat.com>
Date:   Fri Feb 3 15:55:19 2012 +0100

    ui: rewrite disk_print_flags and partition_print_flags
    
    * parted/parted.c (disk_print_flags): Avoid NULL-dereference on
    failed malloc.  Use xrealloc, not ped_realloc.
    (partition_print_flags): Likewise; nearly identical code.

diff --git a/parted/parted.c b/parted/parted.c
index a1b8c2f..789030a 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -860,38 +860,30 @@ error:
 }
 
 static char*
-partition_print_flags (PedPartition* part)
+partition_print_flags (PedPartition const *part)
 {
-        PedPartitionFlag        flag;
-        int                     first_flag;
-        const char*             name;
-        char*                   res = ped_malloc(1);
-        void*                   _res = res;
-
-        *res = '\0';
-
-        first_flag = 1;
-        for (flag = ped_partition_flag_next (0); flag;
-             flag = ped_partition_flag_next (flag)) {
-                if (ped_partition_get_flag (part, flag)) {
-                        if (first_flag)
-                                first_flag = 0;
-                        else {
-                                _res = res;
-                                ped_realloc (&_res, strlen (res) + 1 + 2);
-                                res = _res;
-                                strncat (res, ", ", 2);
-                        }
-
-                        name = _(ped_partition_flag_get_name (flag));
-                        _res = res;
-                        ped_realloc (&_res, strlen (res) + 1 + strlen (name));
-                        res = _res;
-                        strcat(res, name);
-                }
+  char *res = xstrdup ("");
+  if (!part)
+    return res;
+
+  PedPartitionFlag flag;
+  size_t res_buf_len = 1;
+  char const *sep = "";
+  for (flag = ped_partition_flag_next (0); flag;
+       flag = ped_partition_flag_next (flag))
+    {
+      if (ped_partition_get_flag (part, flag))
+        {
+          const char *name = _(ped_partition_flag_get_name (flag));
+          size_t new_len = res_buf_len + strlen (sep) + strlen (name);
+          res = xrealloc (res, new_len);
+          stpcpy (stpcpy (res + res_buf_len - 1, sep), name);
+          res_buf_len = new_len;
+          sep = ", ";
         }
+    }
 
-        return res;
+  return res;
 }
 
 static int
@@ -903,38 +895,28 @@ partition_print (PedPartition* part)
 static char*
 disk_print_flags (PedDisk const *disk)
 {
-        PedDiskFlag     flag;
-        int             first_flag;
-        const char*     name;
-        char*           res = ped_malloc(1);
-        void*           _res = res;
-
-        *res = '\0';
-        if (!disk)
-            return res;
-
-        first_flag = 1;
-        for (flag = ped_disk_flag_next (0); flag;
-             flag = ped_disk_flag_next (flag)) {
-                if (ped_disk_get_flag (disk, flag)) {
-                        if (first_flag)
-                                first_flag = 0;
-                        else {
-                                _res = res;
-                                ped_realloc (&_res, strlen (res) + 1 + 2);
-                                res = _res;
-                                strncat (res, ", ", 2);
-                        }
-
-                        name = _(ped_disk_flag_get_name (flag));
-                        _res = res;
-                        ped_realloc (&_res, strlen (res) + 1 + strlen (name));
-                        res = _res;
-                        strcat(res, name);
-                }
+  char *res = xstrdup ("");
+  if (!disk)
+    return res;
+
+  PedDiskFlag flag;
+  size_t res_buf_len = 1;
+  char const *sep = "";
+  for (flag = ped_disk_flag_next (0); flag;
+       flag = ped_disk_flag_next (flag))
+    {
+      if (ped_disk_get_flag (disk, flag))
+        {
+          const char *name = _(ped_disk_flag_get_name (flag));
+          size_t new_len = res_buf_len + strlen (sep) + strlen (name);
+          res = xrealloc (res, new_len);
+          stpcpy (stpcpy (res + res_buf_len - 1, sep), name);
+          res_buf_len = new_len;
+          sep = ", ";
         }
+    }
 
-        return res;
+  return res;
 }
 
 static void

commit a1e09af3ad3d080056feb6a5aeb91af950a1c5e4
Author: Jim Meyering <meyering at redhat.com>
Date:   Fri Feb 3 16:38:25 2012 +0100

    tests: avoid relatively harmless new "make syntax-check" failure
    
    * tests/t0209-gpt-pmbr_boot.sh: Reverse compare arguments.

diff --git a/tests/t0209-gpt-pmbr_boot.sh b/tests/t0209-gpt-pmbr_boot.sh
index b15cc9c..d62d1cd 100755
--- a/tests/t0209-gpt-pmbr_boot.sh
+++ b/tests/t0209-gpt-pmbr_boot.sh
@@ -26,7 +26,7 @@ dd if=/dev/null of=$dev bs=1 seek=$N || framework_failure
 # create a GPT partition table
 parted -s $dev mklabel gpt > out 2>&1 || fail=1
 # expect no output
-compare out /dev/null || fail=1
+compare /dev/null out || fail=1
 
 # Set the pmbr_boot flag on the PMBR
 parted -s $dev disk_set pmbr_boot on

commit f1c2c13374c6cd2448f4d9d38d101d80b169dfb9
Author: Jim Meyering <meyering at redhat.com>
Date:   Fri Feb 3 16:11:53 2012 +0100

    libparted: remove ped_realloc, now unused
    
    * include/parted/parted.in.h (ped_realloc): Remove declaration.
    * libparted/libparted.c (ped_realloc): Remove definition.

diff --git a/include/parted/parted.in.h b/include/parted/parted.in.h
index fbcb9aa..856b7aa 100644
--- a/include/parted/parted.in.h
+++ b/include/parted/parted.in.h
@@ -47,7 +47,6 @@ extern const char *ped_get_version () _GL_ATTRIBUTE_CONST;
 
 extern void* ped_malloc (size_t size);
 extern void* ped_calloc (size_t size);
-extern int ped_realloc (void** ptr, size_t size);
 extern void free (void* ptr);
 
 #ifdef __cplusplus
diff --git a/libparted/libparted.c b/libparted/libparted.c
index 627bc82..a6d86f0 100644
--- a/libparted/libparted.c
+++ b/libparted/libparted.c
@@ -234,21 +234,6 @@ ped_malloc (size_t size)
 	return mem;
 }
 
-int
-ped_realloc (void** old, size_t size)
-{
-	void*		mem;
-
-	mem = (void*) realloc (*old, size);
-	if (!mem) {
-		ped_exception_throw (PED_EXCEPTION_FATAL, PED_EXCEPTION_CANCEL,
-				     _("Out of memory."));
-		return 0;
-	}
-	*old = mem;
-	return 1;
-}
-
 
 void* ped_calloc (size_t size)
 {
diff --git a/scripts/data/abi/baseline_symbols.txt b/scripts/data/abi/baseline_symbols.txt
index 010a55e..9162f1a 100644
--- a/scripts/data/abi/baseline_symbols.txt
+++ b/scripts/data/abi/baseline_symbols.txt
@@ -381,7 +381,6 @@ FUNC:ped_partition_set_flag
 FUNC:ped_partition_set_name
 FUNC:ped_partition_set_system
 FUNC:ped_partition_type_get_name
-FUNC:ped_realloc
 FUNC:ped_register_disk_type
 FUNC:ped_round_down_to
 FUNC:ped_round_to_nearest



More information about the Parted-commits mailing list