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 --- disk-utils/fdisk-list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'disk-utils/fdisk-list.c') diff --git a/disk-utils/fdisk-list.c b/disk-utils/fdisk-list.c index 6cd582174..b2b528e97 100644 --- a/disk-utils/fdisk-list.c +++ b/disk-utils/fdisk-list.c @@ -380,7 +380,7 @@ int *init_fields(struct fdisk_context *cxt, const char *str, size_t *n) /* extend or replace fields_nids[] according to fields_string */ if (fields_string && string_add_to_idarray(fields_string, fields_ids, FDISK_NFIELDS * 2, - (int *) &fields_nids, fieldname_to_id) < 0) + &fields_nids, fieldname_to_id) < 0) exit(EXIT_FAILURE); done: fields_label = NULL; -- cgit v1.2.3-55-g7522