[LEDE-DEV] [PATCH] libubox: Fix -Wsign-compare and sign conversion warnings
Rosen Penev
rosenp at gmail.com
Sat Jan 28 17:37:55 PST 2017
While at it, also add -Wextra and -Wno-unused-parameter to the
CFLAGS. Compile tested on 32 and 64-bit x86.
Signed-off by: Rosen Penev <rosenp at gmail.com>
---
CMakeLists.txt | 3 +--
base64.c | 6 +++---
blob.c | 12 ++++++------
blob.h | 8 ++++----
blobmsg.c | 2 +-
blobmsg_json.c | 4 ++--
json_script.c | 17 +++++++++--------
kvlist.c | 2 +-
usock.c | 6 +++---
9 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 57804cf..44032df 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,8 +3,7 @@ INCLUDE(CheckLibraryExists)
INCLUDE(CheckFunctionExists)
PROJECT(ubox C)
-ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations)
-
+ADD_DEFINITIONS(-Os -Wall -Wextra -Werror --std=gnu99 -g3 -Wmissing-declarations -Wno-unused-parameter)
OPTION(BUILD_LUA "build Lua plugin" ON)
OPTION(BUILD_EXAMPLES "build examples" ON)
diff --git a/base64.c b/base64.c
index 4186ce8..f4cb5c6 100644
--- a/base64.c
+++ b/base64.c
@@ -142,7 +142,6 @@ int b64_encode(const void *_src, size_t srclength,
size_t datalength = 0;
u_char input[3] = {0};
u_char output[4];
- int i;
while (2 < srclength) {
input[0] = *src++;
@@ -167,7 +166,7 @@ int b64_encode(const void *_src, size_t srclength,
if (0 != srclength) {
/* Get what's left. */
input[0] = input[1] = input[2] = '\0';
- for (i = 0; i < srclength; i++)
+ for (size_t i = 0; i < srclength; i++)
input[i] = *src++;
output[0] = input[0] >> 2;
@@ -200,7 +199,8 @@ int b64_decode(const void *_src, void *dest, size_t targsize)
{
const char *src = _src;
unsigned char *target = dest;
- int tarindex, state, ch;
+ int state, ch;
+ size_t tarindex;
u_char nextbyte;
char *pos;
diff --git a/blob.c b/blob.c
index 03d5e9c..45c3204 100644
--- a/blob.c
+++ b/blob.c
@@ -186,7 +186,7 @@ blob_nest_end(struct blob_buf *buf, void *cookie)
buf->head = attr;
}
-static const int blob_type_minlen[BLOB_ATTR_LAST] = {
+static const size_t blob_type_minlen[BLOB_ATTR_LAST] = {
[BLOB_ATTR_STRING] = 1,
[BLOB_ATTR_INT8] = sizeof(uint8_t),
[BLOB_ATTR_INT16] = sizeof(uint16_t),
@@ -222,18 +222,18 @@ blob_parse(struct blob_attr *attr, struct blob_attr **data, const struct blob_at
{
struct blob_attr *pos;
int found = 0;
- int rem;
+ unsigned int rem;
memset(data, 0, sizeof(struct blob_attr *) * max);
blob_for_each_attr(pos, attr, rem) {
- int id = blob_id(pos);
- int len = blob_len(pos);
+ unsigned int id = blob_id(pos);
+ unsigned int len = blob_len(pos);
- if (id >= max)
+ if ((int)id >= max)
continue;
if (info) {
- int type = info[id].type;
+ unsigned int type = info[id].type;
if (type < BLOB_ATTR_LAST) {
if (!blob_check_type(blob_data(pos), len, type))
diff --git a/blob.h b/blob.h
index a092f5d..3f069da 100644
--- a/blob.h
+++ b/blob.h
@@ -154,25 +154,25 @@ blob_get_u64(const struct blob_attr *attr)
static inline int8_t
blob_get_int8(const struct blob_attr *attr)
{
- return blob_get_u8(attr);
+ return (int8_t)blob_get_u8(attr);
}
static inline int16_t
blob_get_int16(const struct blob_attr *attr)
{
- return blob_get_u16(attr);
+ return (int16_t)blob_get_u16(attr);
}
static inline int32_t
blob_get_int32(const struct blob_attr *attr)
{
- return blob_get_u32(attr);
+ return (int32_t)blob_get_u32(attr);
}
static inline int64_t
blob_get_int64(const struct blob_attr *attr)
{
- return blob_get_u64(attr);
+ return (int64_t)blob_get_u64(attr);
}
static inline const char *
diff --git a/blobmsg.c b/blobmsg.c
index c2bb717..1eddf23 100644
--- a/blobmsg.c
+++ b/blobmsg.c
@@ -67,7 +67,7 @@ int blobmsg_check_array(const struct blob_attr *attr, int type)
{
struct blob_attr *cur;
bool name;
- int rem;
+ unsigned int rem;
int size = 0;
switch (blobmsg_type(attr)) {
diff --git a/blobmsg_json.c b/blobmsg_json.c
index ca9dd1a..c46890c 100644
--- a/blobmsg_json.c
+++ b/blobmsg_json.c
@@ -146,7 +146,7 @@ static bool blobmsg_puts(struct strbuf *s, const char *c, int len)
static void add_separator(struct strbuf *s)
{
const char *indent_chars = "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
- int len;
+ size_t len;
if (!s->indent)
return;
@@ -280,7 +280,7 @@ static void blobmsg_format_json_list(struct strbuf *s, struct blob_attr *attr, i
{
struct blob_attr *pos;
bool first = true;
- int rem = len;
+ unsigned int rem = len;
blobmsg_puts(s, (array ? "[" : "{" ), 1);
s->indent_level++;
diff --git a/json_script.c b/json_script.c
index 463aac8..2d720ae 100644
--- a/json_script.c
+++ b/json_script.c
@@ -95,7 +95,7 @@ const char *json_script_find_var(struct json_script_ctx *ctx, struct blob_attr *
const char *name)
{
struct blob_attr *cur;
- int rem;
+ unsigned int rem;
blobmsg_for_each_attr(cur, vars, rem) {
if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
@@ -164,7 +164,7 @@ static int handle_case(struct json_call *call, struct blob_attr *expr)
{
struct blob_attr *tb[3], *cur;
const char *var;
- int rem;
+ unsigned int rem;
json_get_tuple(expr, tb, BLOBMSG_TYPE_STRING, BLOBMSG_TYPE_TABLE);
if (!tb[1] || !tb[2])
@@ -233,7 +233,7 @@ static int expr_eq_regex(struct json_call *call, struct blob_attr *expr, bool re
struct json_script_ctx *ctx = call->ctx;
struct blob_attr *tb[3], *cur;
const char *var;
- int rem;
+ unsigned int rem;
json_get_tuple(expr, tb, BLOBMSG_TYPE_STRING, 0);
if (!tb[1] || !tb[2])
@@ -277,7 +277,7 @@ static int handle_expr_has(struct json_call *call, struct blob_attr *expr)
{
struct json_script_ctx *ctx = call->ctx;
struct blob_attr *tb[3], *cur;
- int rem;
+ unsigned int rem;
json_get_tuple(expr, tb, 0, 0);
if (!tb[1])
@@ -306,8 +306,8 @@ static int handle_expr_has(struct json_call *call, struct blob_attr *expr)
static int expr_and_or(struct json_call *call, struct blob_attr *expr, bool and)
{
struct blob_attr *cur;
- int ret, rem;
- int i = 0;
+ int ret;
+ unsigned int i = 0, rem;
blobmsg_for_each_attr(cur, expr, rem) {
if (i++ < 1)
@@ -513,7 +513,8 @@ static int cmd_process_strings(struct json_call *call, struct blob_attr *attr)
struct json_script_ctx *ctx = call->ctx;
struct blob_attr *cur;
int args = -1;
- int rem, ret;
+ int ret;
+ unsigned int rem;
void *c;
blob_buf_init(&ctx->buf, 0);
@@ -570,7 +571,7 @@ static int json_process_cmd(struct json_call *call, struct blob_attr *block)
{
struct json_script_ctx *ctx = call->ctx;
struct blob_attr *cur;
- int rem;
+ unsigned int rem;
int ret;
int i = 0;
diff --git a/kvlist.c b/kvlist.c
index a7b6ea0..66fc8cd 100644
--- a/kvlist.c
+++ b/kvlist.c
@@ -75,7 +75,7 @@ bool kvlist_set(struct kvlist *kv, const char *name, const void *data)
{
struct kvlist_node *node;
char *name_buf;
- int len = kv->get_len(kv, data);
+ size_t len = kv->get_len(kv, data);
node = calloc_a(sizeof(struct kvlist_node) + len,
&name_buf, strlen(name) + 1);
diff --git a/usock.c b/usock.c
index 0ce5390..c159a76 100644
--- a/usock.c
+++ b/usock.c
@@ -33,7 +33,7 @@
#include "usock.h"
#include "utils.h"
-static void usock_set_flags(int sock, unsigned int type)
+static void usock_set_flags(int sock, int type)
{
if (!(type & USOCK_NOCLOEXEC))
fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC);
@@ -42,7 +42,7 @@ static void usock_set_flags(int sock, unsigned int type)
fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) | O_NONBLOCK);
}
-static int usock_connect(int type, struct sockaddr *sa, int sa_len, int family, int socktype, bool server)
+static int usock_connect(int type, struct sockaddr *sa, socklen_t sa_len, int family, int socktype, bool server)
{
int sock;
@@ -103,7 +103,7 @@ usock_inet_notimeout(int type, struct addrinfo *result, void *addr)
return -1;
}
-static int poll_restart(struct pollfd *fds, int nfds, int timeout)
+static int poll_restart(struct pollfd *fds, nfds_t nfds, int timeout)
{
struct timespec ts, cur;
int msec = timeout % 1000;
--
2.9.3
More information about the Lede-dev
mailing list