From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1VmRRU-00031f-Ln for mharc-grub-devel@gnu.org; Fri, 29 Nov 2013 12:01:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmRRK-0002i0-HM for grub-devel@gnu.org; Fri, 29 Nov 2013 12:01:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VmRRC-0008C0-53 for grub-devel@gnu.org; Fri, 29 Nov 2013 12:01:14 -0500 Received: from mail-la0-x229.google.com ([2a00:1450:4010:c03::229]:54896) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmRRB-0008Bu-Tr for grub-devel@gnu.org; Fri, 29 Nov 2013 12:01:06 -0500 Received: by mail-la0-f41.google.com with SMTP id eo20so7164097lab.28 for ; Fri, 29 Nov 2013 09:01:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=RM/Z3iFDMRRJunFNFGKrMSMOxNbC37p+HIcgROenBpE=; b=opDJ1goKqoThs0Q6/UfYsLOdg/yV2XLI5uMg1HLVbpSn+IQ1e8GYLNfq7NV1Pn70rX MBIdbioHu5tpdizoZWlE+bTXzihoFkMGkQ6aIp2KsT0xm73sBtgGdjvTIkYrMOEOjFf3 zh7fgubnz6oWoLFK0oKgxKFOmMLnfhQgpBIwx5O+7X5CKO01Pr/BnhRCjd/r4r/wc803 L27NzN9BqFjWkqdIBSKu26TrFN+3RavWIdtKVSqCcvg4xl/kLo0wEriiQ5W1qCvS7cHl NR7WxWJolmutz+n0NFecJ4jJBa0Dx74tLC513NVPQjq78BpcGpIfo8XAkDiLO2MEaPOA 5FNg== X-Received: by 10.112.173.70 with SMTP id bi6mr28981lbc.56.1385744464782; Fri, 29 Nov 2013 09:01:04 -0800 (PST) Received: from localhost.localdomain (ppp91-76-134-134.pppoe.mtu-net.ru. [91.76.134.134]) by mx.google.com with ESMTPSA id ox6sm26286467lbb.6.2013.11.29.09.01.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Nov 2013 09:01:04 -0800 (PST) From: Andrey Borzenkov To: grub-devel@gnu.org Subject: [PATCH] add grub_qsort_strcmp to use when sorting array of strings Date: Fri, 29 Nov 2013 21:01:00 +0400 Message-Id: <1385744460-6624-1-git-send-email-arvidjaar@gmail.com> X-Mailer: git-send-email 1.8.1.4 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::229 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Nov 2013 17:01:23 -0000 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(-) diff --git a/include/grub/util/misc.h b/include/grub/util/misc.h index 6aacf23..192874d 100644 --- a/include/grub/util/misc.h +++ b/include/grub/util/misc.h @@ -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 */ diff --git a/util/grub-install.c b/util/grub-install.c index 5354a6d..1870182 100644 --- a/util/grub-install.c +++ b/util/grub-install.c @@ -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) diff --git a/util/misc.c b/util/misc.c index 0de340b..9eb1fc1 100644 --- a/util/misc.c +++ b/util/misc.c @@ -256,3 +256,11 @@ void grub_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); +} + -- tg: (69ca97c..) u/qsort-fix (depends on: master)