@@ -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)
@@ -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;
@@ -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))
@@ -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 *
@@ -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)) {
@@ -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++;
@@ -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;
@@ -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);
@@ -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;