summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--disk-utils/fdisk-list.c2
-rw-r--r--disk-utils/partx.c3
-rw-r--r--include/strutils.h2
-rw-r--r--lib/strutils.c5
-rw-r--r--misc-utils/findmnt.c12
-rw-r--r--misc-utils/lsblk.c14
-rw-r--r--misc-utils/lslocks.c10
-rw-r--r--sys-utils/losetup.c10
8 files changed, 33 insertions, 25 deletions
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;
diff --git a/disk-utils/partx.c b/disk-utils/partx.c
index f21c388a7..ffc74d698 100644
--- a/disk-utils/partx.c
+++ b/disk-utils/partx.c
@@ -99,7 +99,8 @@ struct colinfo infos[] = {
#define NCOLS ARRAY_SIZE(infos)
/* array with IDs of enabled columns */
-static int columns[NCOLS], ncolumns;
+static int columns[NCOLS];
+size_t ncolumns;
static int verbose;
static int partx_flags;
diff --git a/include/strutils.h b/include/strutils.h
index 847a4219f..8235b5017 100644
--- a/include/strutils.h
+++ b/include/strutils.h
@@ -92,7 +92,7 @@ extern char *size_to_human_string(int options, uint64_t bytes);
extern int string_to_idarray(const char *list, int ary[], size_t arysz,
int (name2id)(const char *, size_t));
extern int string_add_to_idarray(const char *list, int ary[],
- size_t arysz, int *ary_pos,
+ size_t arysz, size_t *ary_pos,
int (name2id)(const char *, size_t));
extern int string_to_bitarray(const char *list, char *ary,
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] == '+')
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index f76ac2e04..afeaa2a3f 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -151,7 +151,7 @@ static struct colinfo infos[] = {
* column twice. That's enough, dynamically allocated array of the columns is
* unnecessary overkill and over-engineering in this case */
static int columns[ARRAY_SIZE(infos) * 2];
-static int ncolumns;
+static size_t ncolumns;
static inline size_t err_columns_index(size_t arysz, size_t idx)
{
@@ -186,7 +186,8 @@ static int match_func(struct libmnt_fs *fs, void *data __attribute__ ((__unused_
static int get_column_id(int num)
{
- assert(num < ncolumns);
+ assert(num >= 0);
+ assert((size_t) num < ncolumns);
assert((size_t) columns[num] < ARRAY_SIZE(infos));
return columns[num];
}
@@ -704,7 +705,7 @@ static char *get_tabdiff_data(struct libmnt_fs *old_fs,
static struct libscols_line *add_line(struct libscols_table *table, struct libmnt_fs *fs,
struct libscols_line *parent)
{
- int i;
+ size_t i;
struct libscols_line *line = scols_table_new_line(table, parent);
if (!line) {
@@ -721,7 +722,7 @@ static struct libscols_line *add_line(struct libscols_table *table, struct libmn
static struct libscols_line *add_tabdiff_line(struct libscols_table *table, struct libmnt_fs *new_fs,
struct libmnt_fs *old_fs, int change)
{
- int i;
+ size_t i;
struct libscols_line *line = scols_table_new_line(table, NULL);
if (!line) {
@@ -1271,9 +1272,10 @@ int main(int argc, char *argv[])
struct libmnt_table *tb = NULL;
char **tabfiles = NULL;
int direction = MNT_ITER_FORWARD;
- int i, c, rc = -1, timeout = -1;
+ int c, rc = -1, timeout = -1;
int ntabfiles = 0, tabtype = 0;
char *outarg = NULL;
+ size_t i;
struct libscols_table *table = NULL;
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index 6c716ea95..1b4ffc128 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -222,7 +222,7 @@ struct lsblk *lsblk; /* global handler */
* column twice. That's enough, dynamically allocated array of the columns is
* unnecessary overkill and over-engineering in this case */
static int columns[ARRAY_SIZE(infos) * 2];
-static int ncolumns;
+static size_t ncolumns;
static inline size_t err_columns_index(size_t arysz, size_t idx)
{
@@ -329,7 +329,8 @@ static int is_maj_included(int maj)
/* array with IDs of enabled columns */
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];
}
@@ -357,7 +358,7 @@ static int column_id_to_number(int id)
{
size_t i;
- for (i = 0; i < (size_t) ncolumns; i++)
+ for (i = 0; i < ncolumns; i++)
if (columns[i] == id)
return i;
return -1;
@@ -1127,7 +1128,7 @@ static void set_scols_data(struct blkdev_cxt *cxt, int col, int id, struct libsc
static void fill_table_line(struct blkdev_cxt *cxt, struct libscols_line *scols_parent)
{
- int i;
+ size_t i;
cxt->scols_line = scols_table_new_line(lsblk->table, scols_parent);
if (!cxt->scols_line)
@@ -1642,8 +1643,9 @@ int main(int argc, char *argv[])
{
struct lsblk _ls = { .sort_id = -1 };
int scols_flags = LSBLK_TREE;
- int i, c, status = EXIT_FAILURE;
+ int c, status = EXIT_FAILURE;
char *outarg = NULL;
+ size_t i;
static const struct option longopts[] = {
{ "all", 0, 0, 'a' },
@@ -1730,7 +1732,7 @@ int main(int argc, char *argv[])
outarg = optarg;
break;
case 'O':
- for (ncolumns = 0 ; ncolumns < (int) ARRAY_SIZE(infos); ncolumns++)
+ for (ncolumns = 0 ; ncolumns < ARRAY_SIZE(infos); ncolumns++)
columns[ncolumns] = ncolumns;
break;
case 'p':
diff --git a/misc-utils/lslocks.c b/misc-utils/lslocks.c
index 9072d6027..e2229adc3 100644
--- a/misc-utils/lslocks.c
+++ b/misc-utils/lslocks.c
@@ -82,7 +82,7 @@ static struct colinfo infos[] = {
};
static int columns[ARRAY_SIZE(infos) * 2];
-static int ncolumns;
+static size_t ncolumns;
static pid_t pid = 0;
@@ -343,7 +343,8 @@ static int column_name_to_id(const char *name, size_t namesz)
static inline 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];
@@ -385,7 +386,7 @@ static pid_t get_blocker(int id, struct list_head *locks)
static void add_scols_line(struct libscols_table *table, struct lock *l, struct list_head *locks)
{
- int i;
+ size_t i;
struct libscols_line *line;
/*
* Whenever cmdname or filename is NULL it is most
@@ -452,7 +453,8 @@ static void add_scols_line(struct libscols_table *table, struct lock *l, struct
static int show_locks(struct list_head *locks)
{
- int i, rc = 0;
+ int rc = 0;
+ size_t i;
struct list_head *p, *pnext;
struct libscols_table *table;
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);