diff options
author | Karel Zak | 2015-04-22 11:08:05 +0200 |
---|---|---|
committer | Karel Zak | 2015-04-22 11:08:05 +0200 |
commit | 40b175084ff4c57468fb67600c8c66703e17cd75 (patch) | |
tree | 25ed8dc26b4afc906bfcc1e58c6be37b687f6eea /sys-utils/losetup.c | |
parent | fdisk, sfdisk: fix -o <list> backend (diff) | |
download | kernel-qcow2-util-linux-40b175084ff4c57468fb67600c8c66703e17cd75.tar.gz kernel-qcow2-util-linux-40b175084ff4c57468fb67600c8c66703e17cd75.tar.xz kernel-qcow2-util-linux-40b175084ff4c57468fb67600c8c66703e17cd75.zip |
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 <kzak@redhat.com>
Diffstat (limited to 'sys-utils/losetup.c')
-rw-r--r-- | sys-utils/losetup.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c index 29084eab2..c2bbd0d14 100644 --- a/sys-utils/losetup.c +++ b/sys-utils/losetup.c @@ -74,11 +74,12 @@ static struct colinfo infos[] = { }; static int columns[ARRAY_SIZE(infos) * 2] = {-1}; -static int ncolumns; +static size_t ncolumns; static int get_column_id(int num) { - assert(num < ncolumns); + assert(num >= 0); + assert((size_t) num < ncolumns); assert(columns[num] < (int) ARRAY_SIZE(infos)); return columns[num]; } @@ -213,7 +214,7 @@ static int delete_all_loops(struct loopdev_cxt *lc) static int set_scols_data(struct loopdev_cxt *lc, struct libscols_line *ln) { - int i; + size_t i; for (i = 0; i < ncolumns; i++) { const char *p = NULL; /* external data */ @@ -292,7 +293,8 @@ static int show_table(struct loopdev_cxt *lc, struct stat sbuf, *st = &sbuf; struct libscols_table *tb; struct libscols_line *ln; - int i, rc = 0; + int rc = 0; + size_t i; scols_init_debug(0); |