]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2009-03-30 Pavel Roskin <proski@gnu.org>
authorproski <proski@localhost>
Tue, 31 Mar 2009 00:22:08 +0000 (00:22 +0000)
committerproski <proski@localhost>
Tue, 31 Mar 2009 00:22:08 +0000 (00:22 +0000)
* fs/hfs.c (grub_hfs_strncasecmp): Integrate into ...
(grub_hfs_cmp_catkeys): ... this.  Don't assume strings to be
zero-terminated, rely only on the strlen value.  Fix comparison
of strings differing in length.

ChangeLog
fs/hfs.c

index 03c09cf1b6d2c2b0c9c244d82a0b61783f85452a..d73c7c9d6275d76329502ff9370a4bfae088aa10 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-03-30  Pavel Roskin  <proski@gnu.org>
+
+       * fs/hfs.c (grub_hfs_strncasecmp): Integrate into ...
+       (grub_hfs_cmp_catkeys): ... this.  Don't assume strings to be
+       zero-terminated, rely only on the strlen value.  Fix comparison
+       of strings differing in length.
+
 2009-03-30  Robert Millan  <rmh@aybabtu.com>
 
        * loader/i386/linux.c (grub_cmd_linux): Check for zImage before
index a923309cf388607d4553ad5ac58945b96ba6a6b9..2ab3ac2fac6ad727d4c0936672485ace2b071e18 100644 (file)
--- a/fs/hfs.c
+++ b/fs/hfs.c
@@ -390,10 +390,10 @@ grub_hfs_mount (grub_disk_t disk)
   return 0;
 }
 
-/* Case insensitive string comparison using HFS character ordering */
+/* Compare the K1 and K2 catalog file keys using HFS character ordering.  */
 static int
-grub_hfs_strncasecmp (const unsigned char *s1, const unsigned char *s2,
-                     grub_size_t n)
+grub_hfs_cmp_catkeys (struct grub_hfs_catalog_key *k1,
+                     struct grub_hfs_catalog_key *k2)
 {
   /* Taken from hfsutils 3.2.6 and converted to a readable form */
   static const unsigned char hfs_charorder[256] = {
@@ -614,40 +614,23 @@ grub_hfs_strncasecmp (const unsigned char *s1, const unsigned char *s2,
     [0xFE] = 214,
     [0xFF] = 215,
   };
+  int i;
+  int cmp;
+  int minlen = (k1->strlen < k2->strlen) ? k1->strlen : k2->strlen;
 
-  if (n == 0)
-    return 0;
+  cmp = (grub_be_to_cpu32 (k1->parent_dir) - grub_be_to_cpu32 (k2->parent_dir));
+  if (cmp != 0)
+    return cmp;
 
-  while (*s1 && *s2 && --n)
+  for (i = 0; i < minlen; i++)
     {
-      if (hfs_charorder[*s1] != hfs_charorder[*s2])
-       break;
-
-      s1++;
-      s2++;
+      cmp = (hfs_charorder[k1->str[i]] - hfs_charorder[k2->str[i]]);
+      if (cmp != 0)
+       return cmp;
     }
 
-  return (int) hfs_charorder[*s1] - (int) hfs_charorder[*s2];
-}
-
-/* Compare the K1 and K2 catalog file keys.  */
-static int
-grub_hfs_cmp_catkeys (struct grub_hfs_catalog_key *k1,
-                     struct grub_hfs_catalog_key *k2)
-{
-  int cmp = (grub_be_to_cpu32 (k1->parent_dir)
-            - grub_be_to_cpu32 (k2->parent_dir));
-  
-  if (cmp != 0)
-    return cmp;
-  
-  cmp = grub_hfs_strncasecmp (k1->str, k2->str, k1->strlen);
-  
-  /* This is required because the compared strings are not of equal
-     length.  */
-  if (cmp == 0 && k1->strlen < k2->strlen)
-    return -1;
-  return cmp;
+  /* Shorter strings precede long ones.  */
+  return (k1->strlen - k2->strlen);
 }