From 40b175084ff4c57468fb67600c8c66703e17cd75 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 22 Apr 2015 11:08:05 +0200 Subject: lib/strutils: fix string_add_to_idarray() int vs. size_t The function uses "int" as argument, but for array size (and index) is better to use unsigned type (size_t). If we mix "size_t" in util (e.g. fdisk) and "int" in lib/strutils.c then result is unexpected behavior on ppc64. # sfdisk --list -o DEVICE,START,SIZE /dev/sdb Disk /dev/sdb: 50 MiB, 52428800 bytes, 102400 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 32768 bytes Disklabel type: gpt Disk identifier: 3B8559DB-33AF-43E9-BEFC-C331D829B539 lt-sfdisk: libfdisk/src/label.c:178: fdisk_label_get_field: Assertion `id > 0' failed. The patch cleanup all code to use size_t everywhere. Signed-off-by: Karel Zak --- lib/strutils.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/strutils.c b/lib/strutils.c index dd776e7ab..b8fd2eb56 100644 --- a/lib/strutils.c +++ b/lib/strutils.c @@ -576,13 +576,12 @@ int string_to_idarray(const char *list, int ary[], size_t arysz, * it adds fields to array instead of replacing them. */ int string_add_to_idarray(const char *list, int ary[], size_t arysz, - int *ary_pos, int (name2id)(const char *, size_t)) + size_t *ary_pos, int (name2id)(const char *, size_t)) { const char *list_add; int r; - if (!list || !*list || !ary_pos || - *ary_pos < 0 || (size_t) *ary_pos > arysz) + if (!list || !*list || !ary_pos || *ary_pos > arysz) return -1; if (list[0] == '+') -- cgit v1.2.3-55-g7522