summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2015-04-22 11:08:05 +0200
committerKarel Zak2015-04-22 11:08:05 +0200
commit40b175084ff4c57468fb67600c8c66703e17cd75 (patch)
tree25ed8dc26b4afc906bfcc1e58c6be37b687f6eea /lib
parentfdisk, sfdisk: fix -o <list> backend (diff)
downloadkernel-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 'lib')
-rw-r--r--lib/strutils.c5
1 files changed, 2 insertions, 3 deletions
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] == '+')