add grub_qsort_strcmp to use when sorting array of strings
PATCH 1/1 add grub_qsort_strcmp to use when sorting array of strings
Compare function used in qsort gets arguments by reference, so strcmp cannot be used directly - it expects pointer to char, but gets pointer to pointer to char.
Introduce new helper grub_qsort_strcmp and use it in grub-install. This helper is going to be used in a couple more places as well so add it to global file, not in grub-install.c.
--- include/grub/util/misc.h | 2 ++ util/grub-install.c | 2 +- util/misc.c | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-)
include/grub/util/misc.h +2 -0
@@ -47,4 +47,6 @@ void grub_util_init_nls (void);void grub_util_host_init (int *argc,char ***argv); +int grub_qsort_strcmp (const void *,const void *); +#endif /* ! GRUB_UTIL_MISC_HEADER */
util/grub-install.c +1 -1
@@ -583,7 +583,7 @@ device_map_check_duplicates (const char *dev_map)fclose (fp); -qsort (d, filled,sizeof (d[0 ]), (int (*) (const void *,const void *))strcmp); +qsort (d, filled,sizeof (d[0 ]), grub_qsort_strcmp);for (i =0 ; i +1 < filled; i++)if (strcmp (d[i], d[i+1 ]) ==0 )
util/misc.c +8 -0
@@ -256,3 +256,11 @@ voidgrub_register_exported_symbols (void) { } + +/* Used in comparison of arrays of strings with qsort */ +int +grub_qsort_strcmp (const void *p1,const void *p2) +{ +return strcmp (*(char **)p1, *(char **)p2); +} +
Signature · 1 line
tg: (69ca97c..) u/qsort-fix (depends on: master)
Quoted 8 lines · Andrey Borzenkov
Compare function used in qsort gets arguments by reference, so strcmp cannot be used directly - it expects pointer to char, but gets pointer to pointer to char.
Introduce new helper
grub_qsort_strcmpand use it in grub-install. This helper is going to be used in a couple more places as well so add it to global file, not ingrub-install.c.
Nice catch. But I don't we have enough use for grub_qsort_strcmp to make it global. Can you make it static in grub-install.c ?
Quoted 47 lines
--- include/grub/util/misc.h | 2 ++ util/grub-install.c | 2 +- util/misc.c | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-)include/grub/util/misc.h +2
-0@@ -47,4 +47,6 @@ void grub_util_init_nls (void);void grub_util_host_init (int *argc,char ***argv); +int grub_qsort_strcmp (const void *,const void *); +#endif /* ! GRUB_UTIL_MISC_HEADER */ util/grub-install.c +1
-1@@ -583,7 +583,7 @@ device_map_check_duplicates (const char *dev_map)fclose (fp); -qsort (d, filled,sizeof (d[0 ]), (int (*) (const void *,const void *))strcmp); +qsort (d, filled,sizeof (d[0 ]), grub_qsort_strcmp);for (i =0 ; i +1 < filled; i++)if (strcmp (d[i], d[i+1 ]) ==0 )util/misc.c +8
-0@@ -256,3 +256,11 @@ voidgrub_register_exported_symbols (void) { } + +/* Used in comparison of arrays of strings with qsort */ +int +grub_qsort_strcmp (const void *p1,const void *p2) +{ +return strcmp (*(char **)p1, *(char **)p2); +} +
В Sat, 30 Nov 2013 11:39:12 +0100
Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]> пишет:
Quoted 11 lines · Andrey Borzenkov
Quoted 8 lines
Compare function used in qsort gets arguments by reference, so strcmp cannot be used directly - it expects pointer to char, but gets pointer to pointer to char.
Introduce new helper
grub_qsort_strcmpand use it in grub-install. This helper is going to be used in a couple more places as well so add it to global file, not ingrub-install.c.Nice catch. But I don't we have enough use for
grub_qsort_strcmpto make it global. Can you make it static ingrub-install.c?
I have pending patches to sort long lists in help output of commands (grub-mkimage and grub-probe target lists). They are long enough to wish some ordering.
Quoted 12 lines · Andrey Borzenkov
В Sat, 30 Nov 2013 11:39:12 +0100
Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]> пишет:Quoted 9 lines · Andrey Borzenkov
Quoted 8 lines
Compare function used in qsort gets arguments by reference, so strcmp cannot be used directly - it expects pointer to char, but gets pointer to pointer to char.
Introduce new helper
grub_qsort_strcmpand use it in grub-install. This helper is going to be used in a couple more places as well so add it to global file, not ingrub-install.c.
Quoted 7 lines
Quoted 2 lines
Nice catch. But I don't we have enough use for
grub_qsort_strcmpto make it global. Can you make it static ingrub-install.c?I have pending patches to sort long lists in help output of commands (grub-mkimage and grub-probe target lists). They are long enough to wish some ordering.
Ok, then go ahead.
Quoted 7 lines
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel