[2053] 2009-03-30 Pavel Roskin <[email protected]>

Pavel Roskin <[email protected]>
Newsgroups gmane.comp.boot-loaders.grub.cvs
Message-ID <[email protected]>
Revision: 2053
          http://svn.sv.gnu.org/viewvc/?view=rev&root=grub&revision=2053
Author:   proski
Date:     2009-03-31 00:22:08 +0000 (Tue, 31 Mar 2009)
Log Message:
-----------
2009-03-30  Pavel Roskin  <[email protected]>

	* 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.

Modified Paths:
--------------
    trunk/grub2/ChangeLog
    trunk/grub2/fs/hfs.c

Modified: trunk/grub2/ChangeLog
===================================================================
--- trunk/grub2/ChangeLog	2009-03-30 22:22:31 UTC (rev 2052)
+++ trunk/grub2/ChangeLog	2009-03-31 00:22:08 UTC (rev 2053)
@@ -1,3 +1,10 @@
+2009-03-30  Pavel Roskin  <[email protected]>
+
+	* 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  <[email protected]>
 
 	* loader/i386/linux.c (grub_cmd_linux): Check for zImage before

Modified: trunk/grub2/fs/hfs.c
===================================================================
--- trunk/grub2/fs/hfs.c	2009-03-30 22:22:31 UTC (rev 2052)
+++ trunk/grub2/fs/hfs.c	2009-03-31 00:22:08 UTC (rev 2053)
@@ -390,10 +390,10 @@
   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,43 +614,26 @@
     [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];
+  /* Shorter strings precede long ones.  */
+  return (k1->strlen - k2->strlen);
 }
 
-/* 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;
-}
 
-
 /* Compare the K1 and K2 extent overflow file keys.  */
 static int
 grub_hfs_cmp_extkeys (struct grub_hfs_extent_key *k1,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.