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.
This commit is contained in:
parent
92f33540d8
commit
6a003ed1be
2 changed files with 24 additions and 34 deletions
|
@ -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>
|
2009-03-30 Robert Millan <rmh@aybabtu.com>
|
||||||
|
|
||||||
* loader/i386/linux.c (grub_cmd_linux): Check for zImage before
|
* loader/i386/linux.c (grub_cmd_linux): Check for zImage before
|
||||||
|
|
47
fs/hfs.c
47
fs/hfs.c
|
@ -390,10 +390,10 @@ grub_hfs_mount (grub_disk_t disk)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Case insensitive string comparison using HFS character ordering */
|
/* Compare the K1 and K2 catalog file keys using HFS character ordering. */
|
||||||
static int
|
static int
|
||||||
grub_hfs_strncasecmp (const unsigned char *s1, const unsigned char *s2,
|
grub_hfs_cmp_catkeys (struct grub_hfs_catalog_key *k1,
|
||||||
grub_size_t n)
|
struct grub_hfs_catalog_key *k2)
|
||||||
{
|
{
|
||||||
/* Taken from hfsutils 3.2.6 and converted to a readable form */
|
/* Taken from hfsutils 3.2.6 and converted to a readable form */
|
||||||
static const unsigned char hfs_charorder[256] = {
|
static const unsigned char hfs_charorder[256] = {
|
||||||
|
@ -614,42 +614,25 @@ grub_hfs_strncasecmp (const unsigned char *s1, const unsigned char *s2,
|
||||||
[0xFE] = 214,
|
[0xFE] = 214,
|
||||||
[0xFF] = 215,
|
[0xFF] = 215,
|
||||||
};
|
};
|
||||||
|
int i;
|
||||||
|
int cmp;
|
||||||
|
int minlen = (k1->strlen < k2->strlen) ? k1->strlen : k2->strlen;
|
||||||
|
|
||||||
if (n == 0)
|
cmp = (grub_be_to_cpu32 (k1->parent_dir) - grub_be_to_cpu32 (k2->parent_dir));
|
||||||
return 0;
|
|
||||||
|
|
||||||
while (*s1 && *s2 && --n)
|
|
||||||
{
|
|
||||||
if (hfs_charorder[*s1] != hfs_charorder[*s2])
|
|
||||||
break;
|
|
||||||
|
|
||||||
s1++;
|
|
||||||
s2++;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
if (cmp != 0)
|
||||||
return cmp;
|
return cmp;
|
||||||
|
|
||||||
cmp = grub_hfs_strncasecmp (k1->str, k2->str, k1->strlen);
|
for (i = 0; i < minlen; i++)
|
||||||
|
{
|
||||||
/* This is required because the compared strings are not of equal
|
cmp = (hfs_charorder[k1->str[i]] - hfs_charorder[k2->str[i]]);
|
||||||
length. */
|
if (cmp != 0)
|
||||||
if (cmp == 0 && k1->strlen < k2->strlen)
|
|
||||||
return -1;
|
|
||||||
return cmp;
|
return cmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Shorter strings precede long ones. */
|
||||||
|
return (k1->strlen - k2->strlen);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Compare the K1 and K2 extent overflow file keys. */
|
/* Compare the K1 and K2 extent overflow file keys. */
|
||||||
static int
|
static int
|
||||||
|
|
Loading…
Add table
Reference in a new issue