]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/kern/partition.c (grub_partition_get_name): Fix reverse
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Wed, 8 Feb 2012 18:53:46 +0000 (19:53 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Wed, 8 Feb 2012 18:53:46 +0000 (19:53 +0100)
iteration of partitions.

ChangeLog
grub-core/kern/partition.c

index a3ad2aa006c6cb343017dc6b1f53102d235cdba6..eb0289b48ec0ffe8c97ec5fb530381e63eb97538 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2012-02-08  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * grub-core/kern/partition.c (grub_partition_get_name): Fix reverse
+       iteration of partitions.
+
 2012-02-08  Vladimir Serbinenko  <phcoder@gmail.com>
 
        Improve gettext support. Stylistic fixes and error handling fixes while
index a083f5cbbb8991e239f7c64627706d63523d5f27..4e6a98d186dfad51129b40d1d71e08e8f7ed8449 100644 (file)
@@ -224,22 +224,33 @@ char *
 grub_partition_get_name (const grub_partition_t partition)
 {
   char *out = 0, *ptr;
-  grub_size_t needlen = 0;
+  grub_size_t needlen;
   grub_partition_t part;
+  if (!partition)
+    return grub_strdup ("");
   for (part = partition; part; part = part->parent)
     /* Even on 64-bit machines this buffer is enough to hold
        longest number.  */
-    needlen += grub_strlen (part->partmap->name) + 27;
-  out = grub_malloc (needlen);
+    needlen += grub_strlen (part->partmap->name) + 1 + 27;
+  out = grub_malloc (needlen + 1);
   if (!out)
     return NULL;
 
-  ptr = out;
+  ptr = out + needlen;
+  *ptr = 0;
   for (part = partition; part; part = part->parent)
     {
-      grub_snprintf (ptr, needlen - (out - ptr), "%s%d", part->partmap->name,
-                    part->number + 1);
-      ptr += grub_strlen (ptr);
+      char buf[27];
+      grub_size_t len;
+      grub_snprintf (buf, sizeof (buf), "%d", part->number + 1);
+      len = grub_strlen (buf);
+      ptr -= len;
+      grub_memcpy (ptr, buf, len);
+      len = grub_strlen (part->partmap->name);
+      ptr -= len;
+      grub_memcpy (ptr, part->partmap->name, len);
+      *--ptr = ',';
     }
+  grub_memmove (out, ptr + 1, out + needlen - ptr);
   return out;
 }