Skip to content

Commit

Permalink
fix(install): use unsigned int instead of unsigned
Browse files Browse the repository at this point in the history
Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
  • Loading branch information
sshedi authored and johannbg committed Aug 7, 2021
1 parent b0bf818 commit 74a4179
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 64 deletions.
40 changes: 20 additions & 20 deletions src/install/hashmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ struct Hashmap {
compare_func_t compare_func;

struct hashmap_entry *iterate_list_head, *iterate_list_tail;
unsigned n_entries;
unsigned int n_entries;
};

#define BY_HASH(h) ((struct hashmap_entry**) ((uint8_t*) (h) + ALIGN(sizeof(Hashmap))))

unsigned string_hash_func(const void *p)
unsigned int string_hash_func(const void *p)
{
unsigned hash = 5381;
unsigned int hash = 5381;
const signed char *c;

/* DJB's hash function */

for (c = p; *c; c++)
hash = (hash << 5) + hash + (unsigned)*c;
hash = (hash << 5) + hash + (unsigned int)*c;

return hash;
}
Expand All @@ -63,7 +63,7 @@ int string_compare_func(const void *a, const void *b)
return strcmp(a, b);
}

unsigned trivial_hash_func(const void *p)
unsigned int trivial_hash_func(const void *p)
{
return PTR_TO_UINT(p);
}
Expand Down Expand Up @@ -107,7 +107,7 @@ int hashmap_ensure_allocated(Hashmap **h, hash_func_t hash_func, compare_func_t
return 0;
}

static void link_entry(Hashmap *h, struct hashmap_entry *e, unsigned hash)
static void link_entry(Hashmap *h, struct hashmap_entry *e, unsigned int hash)
{
assert(h);
assert(e);
Expand Down Expand Up @@ -135,7 +135,7 @@ static void link_entry(Hashmap *h, struct hashmap_entry *e, unsigned hash)
assert(h->n_entries >= 1);
}

static void unlink_entry(Hashmap *h, struct hashmap_entry *e, unsigned hash)
static void unlink_entry(Hashmap *h, struct hashmap_entry *e, unsigned int hash)
{
assert(h);
assert(e);
Expand Down Expand Up @@ -167,7 +167,7 @@ static void unlink_entry(Hashmap *h, struct hashmap_entry *e, unsigned hash)
static void remove_entry(Hashmap *h, struct hashmap_entry **ep)
{
struct hashmap_entry *e = *ep;
unsigned hash;
unsigned int hash;

assert(h);
assert(e);
Expand Down Expand Up @@ -212,7 +212,7 @@ void hashmap_clear(Hashmap *h)
}
}

static struct hashmap_entry *hash_scan(Hashmap *h, unsigned hash, const void *key)
static struct hashmap_entry *hash_scan(Hashmap *h, unsigned int hash, const void *key)
{
struct hashmap_entry *e;
assert(h);
Expand All @@ -228,7 +228,7 @@ static struct hashmap_entry *hash_scan(Hashmap *h, unsigned hash, const void *ke
int hashmap_put(Hashmap *h, const void *key, void *value)
{
struct hashmap_entry *e;
unsigned hash;
unsigned int hash;

assert(h);

Expand Down Expand Up @@ -258,7 +258,7 @@ int hashmap_put(Hashmap *h, const void *key, void *value)
int hashmap_replace(Hashmap *h, const void *key, void *value)
{
struct hashmap_entry *e;
unsigned hash;
unsigned int hash;

assert(h);

Expand All @@ -275,7 +275,7 @@ int hashmap_replace(Hashmap *h, const void *key, void *value)

void *hashmap_get(Hashmap *h, const void *key)
{
unsigned hash;
unsigned int hash;
struct hashmap_entry *e;

if (!h)
Expand All @@ -292,7 +292,7 @@ void *hashmap_get(Hashmap *h, const void *key)
void *hashmap_remove(Hashmap *h, const void *key)
{
struct hashmap_entry *e;
unsigned hash;
unsigned int hash;
void *data;

if (!h)
Expand All @@ -312,7 +312,7 @@ void *hashmap_remove(Hashmap *h, const void *key)
int hashmap_remove_and_put(Hashmap *h, const void *old_key, const void *new_key, void *value)
{
struct hashmap_entry *e;
unsigned old_hash, new_hash;
unsigned int old_hash, new_hash;

if (!h)
return -ENOENT;
Expand All @@ -338,7 +338,7 @@ int hashmap_remove_and_put(Hashmap *h, const void *old_key, const void *new_key,
int hashmap_remove_and_replace(Hashmap *h, const void *old_key, const void *new_key, void *value)
{
struct hashmap_entry *e, *k;
unsigned old_hash, new_hash;
unsigned int old_hash, new_hash;

if (!h)
return -ENOENT;
Expand Down Expand Up @@ -366,7 +366,7 @@ int hashmap_remove_and_replace(Hashmap *h, const void *old_key, const void *new_
void *hashmap_remove_value(Hashmap *h, const void *key, void *value)
{
struct hashmap_entry *e;
unsigned hash;
unsigned int hash;

if (!h)
return NULL;
Expand Down Expand Up @@ -458,7 +458,7 @@ void *hashmap_iterate_backwards(Hashmap *h, Iterator *i, const void **key)

void *hashmap_iterate_skip(Hashmap *h, const void *key, Iterator *i)
{
unsigned hash;
unsigned int hash;
struct hashmap_entry *e;

if (!h)
Expand Down Expand Up @@ -546,7 +546,7 @@ void *hashmap_steal_first_key(Hashmap *h)
return key;
}

unsigned hashmap_size(Hashmap *h)
unsigned int hashmap_size(Hashmap *h)
{

if (!h)
Expand Down Expand Up @@ -597,7 +597,7 @@ void hashmap_move(Hashmap *h, Hashmap *other)
return;

for (e = other->iterate_list_head; e; e = n) {
unsigned h_hash, other_hash;
unsigned int h_hash, other_hash;

n = e->iterate_next;

Expand All @@ -615,7 +615,7 @@ void hashmap_move(Hashmap *h, Hashmap *other)

int hashmap_move_one(Hashmap *h, Hashmap *other, const void *key)
{
unsigned h_hash, other_hash;
unsigned int h_hash, other_hash;
struct hashmap_entry *e;

if (!other)
Expand Down
8 changes: 4 additions & 4 deletions src/install/hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ typedef _IteratorStruct *Iterator;
#define ITERATOR_FIRST ((Iterator) 0)
#define ITERATOR_LAST ((Iterator) -1)

typedef unsigned (*hash_func_t)(const void *p);
typedef unsigned int (*hash_func_t)(const void *p);
typedef int (*compare_func_t)(const void *a, const void *b);

unsigned string_hash_func(const void *p);
unsigned int string_hash_func(const void *p);
int string_compare_func(const void *a, const void *b);

unsigned trivial_hash_func(const void *p);
unsigned int trivial_hash_func(const void *p);
int trivial_compare_func(const void *a, const void *b);

Hashmap *hashmap_new(hash_func_t hash_func, compare_func_t compare_func);
Expand All @@ -60,7 +60,7 @@ int hashmap_merge(Hashmap *h, Hashmap *other);
void hashmap_move(Hashmap *h, Hashmap *other);
int hashmap_move_one(Hashmap *h, Hashmap *other, const void *key);

unsigned hashmap_size(Hashmap *h);
unsigned int hashmap_size(Hashmap *h);
bool hashmap_isempty(Hashmap *h);

void *hashmap_iterate(Hashmap *h, Iterator *i, const void **key);
Expand Down
15 changes: 8 additions & 7 deletions src/install/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static int write_to_console(int level, const char *file, unsigned int line, cons
{

struct iovec iovec[5];
unsigned n = 0;
unsigned int n = 0;

if (console_fd < 0)
return 0;
Expand All @@ -130,7 +130,7 @@ static int write_to_console(int level, const char *file, unsigned int line, cons
return 1;
}

static int log_dispatch(int level, const char *file, int line, const char *func, char *buffer)
static int log_dispatch(int level, const char *file, unsigned int line, const char *func, char *buffer)
{

int r = 0;
Expand Down Expand Up @@ -163,7 +163,7 @@ static int log_dispatch(int level, const char *file, int line, const char *func,
return r;
}

int log_metav(int level, const char *file, int line, const char *func, const char *format, va_list ap)
int log_metav(int level, const char *file, unsigned int line, const char *func, const char *format, va_list ap)
{

char buffer[LINE_MAX];
Expand All @@ -182,7 +182,7 @@ int log_metav(int level, const char *file, int line, const char *func, const cha
return r;
}

int log_meta(int level, const char *file, int line, const char *func, const char *format, ...)
int log_meta(int level, const char *file, unsigned int line, const char *func, const char *format, ...)
{

int r;
Expand All @@ -197,7 +197,8 @@ int log_meta(int level, const char *file, int line, const char *func, const char

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
_noreturn_ static void log_assert(const char *text, const char *file, int line, const char *func, const char *format)
_noreturn_ static void log_assert(const char *text, const char *file, unsigned int line, const char *func,
const char *format)
{
static char buffer[LINE_MAX];

Expand All @@ -212,12 +213,12 @@ _noreturn_ static void log_assert(const char *text, const char *file, int line,

#pragma GCC diagnostic pop

_noreturn_ void log_assert_failed(const char *text, const char *file, int line, const char *func)
_noreturn_ void log_assert_failed(const char *text, const char *file, unsigned int line, const char *func)
{
log_assert(text, file, line, func, "Assertion '%s' failed at %s:%u, function %s(). Aborting.");
}

_noreturn_ void log_assert_failed_unreachable(const char *text, const char *file, int line, const char *func)
_noreturn_ void log_assert_failed_unreachable(const char *text, const char *file, unsigned int line, const char *func)
{
log_assert(text, file, line, func, "Code should not be reached '%s' at %s:%u, function %s(). Aborting.");
}
Expand Down
9 changes: 5 additions & 4 deletions src/install/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ void log_close_console(void);

void log_parse_environment(void);

int log_meta(int level, const char *file, int line, const char *func, const char *format, ...) _printf_attr_(5, 6);
int log_meta(int level, const char *file, unsigned int line, const char *func,
const char *format, ...) _printf_attr_(5, 6);

int log_metav(int level, const char *file, int line, const char *func, const char *format, va_list ap);
int log_metav(int level, const char *file, unsigned int line, const char *func, const char *format, va_list ap);

_noreturn_ void log_assert_failed(const char *text, const char *file, int line, const char *func);
_noreturn_ void log_assert_failed_unreachable(const char *text, const char *file, int line, const char *func);
_noreturn_ void log_assert_failed(const char *text, const char *file, unsigned int line, const char *func);
_noreturn_ void log_assert_failed_unreachable(const char *text, const char *file, unsigned int line, const char *func);

/* This modifies the buffer passed! */
int log_dump_internal(int level, const char *file, int line, const char *func, char *buffer);
Expand Down
8 changes: 4 additions & 4 deletions src/install/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ static inline size_t ALIGN_TO(size_t l, size_t ali)
_i->iov_len = strlen(_s); \
} while(false)

static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, unsigned n)
static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, unsigned int n)
{
unsigned j;
unsigned int j;
size_t r = 0;

for (j = 0; j < n; j++)
Expand All @@ -201,9 +201,9 @@ static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, unsigned n)
return r;
}

static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k)
static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned int n, size_t k)
{
unsigned j;
unsigned int j;

for (j = 0; j < n; j++) {
size_t sub;
Expand Down
12 changes: 6 additions & 6 deletions src/install/strv.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ char **strv_copy(char *const *l)

unsigned int strv_length(char *const *l)
{
unsigned n = 0;
unsigned int n = 0;

if (!l)
return 0;
Expand All @@ -105,7 +105,7 @@ char **strv_new_ap(const char *x, va_list ap)
{
const char *s;
char **a;
unsigned n = 0, i = 0;
unsigned int n = 0, i = 0;
va_list aq;

/* As a special trick we ignore all listed strings that equal
Expand Down Expand Up @@ -248,7 +248,7 @@ char **strv_split(const char *s, const char *separator)
char *state;
char *w;
size_t l;
unsigned n, i;
unsigned int n, i;
char **r;

assert(s);
Expand Down Expand Up @@ -282,7 +282,7 @@ char **strv_split_quoted(const char *s)
char *state;
char *w;
size_t l;
unsigned n, i;
unsigned int n, i;
char **r;

assert(s);
Expand Down Expand Up @@ -406,7 +406,7 @@ char **strv_append(char **l, const char *s)
int strv_push(char ***l, char *value)
{
char **c;
unsigned n;
unsigned int n;

if (!value)
return 0;
Expand Down Expand Up @@ -510,7 +510,7 @@ char **strv_remove_prefix(char **l, const char *s)
char **strv_parse_nulstr(const char *s, size_t l)
{
const char *p;
unsigned c = 0, i = 0;
unsigned int c = 0, i = 0;
char **v;

assert(s || l == 0);
Expand Down
2 changes: 1 addition & 1 deletion src/install/strv.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void strv_print(char **l);
if (!first) \
_l = (char**) &first; \
else { \
unsigned _n; \
unsigned int _n; \
va_list _ap; \
\
_n = 1; \
Expand Down
8 changes: 4 additions & 4 deletions src/install/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void close_nointr_nofail(int fd)
int open_terminal(const char *name, int mode)
{
int fd, r;
unsigned c = 0;
unsigned int c = 0;

/*
* If a TTY is in the process of being closed opening it might
Expand Down Expand Up @@ -161,7 +161,7 @@ bool is_main_thread(void)
return cached > 0;
}

int safe_atou(const char *s, unsigned *ret_u)
int safe_atou(const char *s, unsigned int *ret_u)
{
char *x = NULL;
unsigned long l;
Expand All @@ -175,10 +175,10 @@ int safe_atou(const char *s, unsigned *ret_u)
if (!x || *x || errno)
return errno ? -errno : -EINVAL;

if ((unsigned long)(unsigned)l != l)
if ((unsigned long)(unsigned int)l != l)
return -ERANGE;

*ret_u = (unsigned)l;
*ret_u = (unsigned int)l;
return 0;
}

Expand Down
Loading

0 comments on commit 74a4179

Please sign in to comment.