all: Add 'U' suffix when using unsigned variables

Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
This commit is contained in:
Patrik Flykt 2019-03-26 19:57:45 -06:00 committed by Kumar Gala
commit 24d71431e9
559 changed files with 2331 additions and 2328 deletions

View file

@ -199,8 +199,8 @@ char *lwm2m_sprint_ip_addr(const struct sockaddr *addr)
static u8_t to_hex_digit(u8_t digit)
{
if (digit >= 10) {
return digit - 10 + 'a';
if (digit >= 10U) {
return digit - 10U + 'a';
}
return digit + '0';
@ -264,7 +264,7 @@ init_block_ctx(const u8_t *token, u8_t tkl, struct block_context **ctx)
*ctx = NULL;
timestamp = k_uptime_get();
for (i = 0; i < NUM_BLOCK1_CONTEXT; i++) {
if (block1_contexts[i].tkl == 0) {
if (block1_contexts[i].tkl == 0U) {
*ctx = &block1_contexts[i];
break;
}
@ -428,7 +428,7 @@ static int engine_add_observer(struct lwm2m_message *msg,
return -EINVAL;
}
if (!token || (tkl == 0 || tkl > MAX_TOKEN_LEN)) {
if (!token || (tkl == 0U || tkl > MAX_TOKEN_LEN)) {
LOG_ERR("token(%p) and token length(%u) must be valid.",
token, tkl);
return -EINVAL;
@ -469,7 +469,7 @@ static int engine_add_observer(struct lwm2m_message *msg,
}
/* check if object instance exists */
if (msg->path.level >= 2) {
if (msg->path.level >= 2U) {
obj_inst = get_engine_obj_inst(msg->path.obj_id,
msg->path.obj_inst_id);
if (!obj_inst) {
@ -485,7 +485,7 @@ static int engine_add_observer(struct lwm2m_message *msg,
}
/* check if resource exists */
if (msg->path.level >= 3) {
if (msg->path.level >= 3U) {
for (i = 0; i < obj_inst->resource_count; i++) {
if (obj_inst->resources[i].res_id == msg->path.res_id) {
break;
@ -561,7 +561,7 @@ static int engine_remove_observer(const u8_t *token, u8_t tkl)
struct observe_node *obs, *found_obj = NULL;
sys_snode_t *prev_node = NULL;
if (!token || (tkl == 0 || tkl > MAX_TOKEN_LEN)) {
if (!token || (tkl == 0U || tkl > MAX_TOKEN_LEN)) {
LOG_ERR("token(%p) and token length(%u) must be valid.",
token, tkl);
return -EINVAL;
@ -816,7 +816,7 @@ static u16_t atou16(u8_t *buf, u16_t buflen, u16_t *len)
/* we should get a value first - consume all numbers */
while (pos < buflen && isdigit(buf[pos])) {
val = val * 10 + (buf[pos] - '0');
val = val * 10U + (buf[pos] - '0');
pos++;
}
@ -878,7 +878,7 @@ static int coap_options_to_path(struct coap_option *opt, int options_count,
for (int i = 0; i < options_count; i++) {
*id[i] = atou16(opt[i].value, opt[i].len, &len);
if (len == 0 || opt[i].len != len) {
if (len == 0U || opt[i].len != len) {
path->level = i;
break;
}
@ -961,7 +961,7 @@ int lwm2m_init_message(struct lwm2m_message *msg)
* msg->tkl == 0 is for a new TOKEN
* msg->tkl == LWM2M_MSG_TOKEN_LEN_SKIP means dont set
*/
if (msg->tkl == 0) {
if (msg->tkl == 0U) {
tokenlen = 0U;
token = coap_next_token();
} else if (msg->token && msg->tkl != LWM2M_MSG_TOKEN_LEN_SKIP) {
@ -1077,7 +1077,7 @@ u16_t lwm2m_get_rd_data(u8_t *client_data, u16_t size)
}
/* Only report <OBJ_ID> when no instance available */
if (obj->instance_count == 0) {
if (obj->instance_count == 0U) {
len = snprintk(temp, sizeof(temp), "%s</%u>",
(pos > 0) ? "," : "", obj->obj_id);
if (pos + len >= size) {
@ -1271,7 +1271,7 @@ static int path_to_objs(const struct lwm2m_obj_path *path,
return -ENOENT;
}
if (!oi->resources || oi->resource_count == 0) {
if (!oi->resources || oi->resource_count == 0U) {
LOG_ERR("obj instance has no resources");
return -EINVAL;
}
@ -1323,7 +1323,7 @@ int lwm2m_engine_create_obj_inst(char *pathstr)
return ret;
}
if (path.level != 2) {
if (path.level != 2U) {
LOG_ERR("path must have 2 parts");
return -EINVAL;
}
@ -1943,7 +1943,7 @@ static int lwm2m_read_handler(struct lwm2m_engine_obj_inst *obj_inst,
if (res->multi_count_var != NULL) {
/* if multi_count_var is 0 (none assigned) return NOT_FOUND */
if (*res->multi_count_var == 0) {
if (*res->multi_count_var == 0U) {
return -ENOENT;
}
@ -2052,7 +2052,7 @@ size_t lwm2m_engine_get_opaque_more(struct lwm2m_input_context *in,
}
in->opaque_len -= in_len;
if (in->opaque_len == 0) {
if (in->opaque_len == 0U) {
*last_block = true;
}
@ -2304,16 +2304,16 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
}
/* get lwm2m_attr slist */
if (msg->path.level == 3) {
if (msg->path.level == 3U) {
ret = path_to_objs(&msg->path, NULL, NULL, &res);
if (ret < 0) {
return ret;
}
ref = res;
} else if (msg->path.level == 1) {
} else if (msg->path.level == 1U) {
ref = obj;
} else if (msg->path.level == 2) {
} else if (msg->path.level == 2U) {
obj_inst = get_engine_obj_inst(msg->path.obj_id,
msg->path.obj_inst_id);
if (!obj_inst) {
@ -2373,7 +2373,7 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
}
/* gt/lt/st cannot be assigned to obj/obj_inst unless unset */
if (plen == 2 && msg->path.level <= 2) {
if (plen == 2 && msg->path.level <= 2U) {
return -EEXIST;
}
@ -2681,10 +2681,10 @@ int lwm2m_perform_read_op(struct lwm2m_engine_obj *obj,
int ret = 0, index;
u8_t num_read = 0U;
if (msg->path.level >= 2) {
if (msg->path.level >= 2U) {
obj_inst = get_engine_obj_inst(msg->path.obj_id,
msg->path.obj_inst_id);
} else if (msg->path.level == 1) {
} else if (msg->path.level == 1U) {
/* find first obj_inst with path's obj_id */
obj_inst = next_engine_obj_inst(msg->path.obj_id, -1);
}
@ -2713,14 +2713,14 @@ int lwm2m_perform_read_op(struct lwm2m_engine_obj *obj,
engine_put_begin(&msg->out, &msg->path);
while (obj_inst) {
if (!obj_inst->resources || obj_inst->resource_count == 0) {
if (!obj_inst->resources || obj_inst->resource_count == 0U) {
goto move_forward;
}
/* update the obj_inst_id as we move through the instances */
msg->path.obj_inst_id = obj_inst->obj_inst_id;
if (msg->path.level <= 1) {
if (msg->path.level <= 1U) {
/* start instance formatting */
engine_put_begin_oi(&msg->out, &msg->path);
}
@ -2761,7 +2761,7 @@ int lwm2m_perform_read_op(struct lwm2m_engine_obj *obj,
LOG_ERR("READ OP: %d", ret);
}
} else {
num_read += 1;
num_read += 1U;
}
/* end resource formatting */
@ -2778,12 +2778,12 @@ int lwm2m_perform_read_op(struct lwm2m_engine_obj *obj,
}
move_forward:
if (msg->path.level <= 1) {
if (msg->path.level <= 1U) {
/* end instance formatting */
engine_put_end_oi(&msg->out, &msg->path);
}
if (msg->path.level <= 1) {
if (msg->path.level <= 1U) {
/* advance to the next object instance */
obj_inst = next_engine_obj_inst(msg->path.obj_id,
obj_inst->obj_inst_id);
@ -2798,7 +2798,7 @@ move_forward:
memcpy(&msg->path, &temp_path, sizeof(temp_path));
/* did not read anything even if we should have - on single item */
if (ret == 0 && num_read == 0 && msg->path.level == 3) {
if (ret == 0 && num_read == 0U && msg->path.level == 3U) {
return -ENOENT;
}
@ -2861,7 +2861,7 @@ static int do_discover_op(struct lwm2m_message *msg, bool well_known)
* ref: lwm2m spec 20170208-A table 11
*/
if (!msg->ctx->bootstrap_mode && !well_known &&
(msg->path.level == 0 ||
(msg->path.level == 0U ||
(msg->path.level > 0 &&
msg->path.obj_id == LWM2M_OBJECT_SECURITY_ID))) {
return -EPERM;
@ -2923,7 +2923,7 @@ static int do_discover_op(struct lwm2m_message *msg, bool well_known)
continue;
}
if (msg->path.level == 1) {
if (msg->path.level == 1U) {
snprintk(disc_buf, sizeof(disc_buf), "%s</%u>",
reported ? "," : "",
obj_inst->obj->obj_id);
@ -2950,7 +2950,7 @@ static int do_discover_op(struct lwm2m_message *msg, bool well_known)
continue;
}
if (msg->path.level == 2) {
if (msg->path.level == 2U) {
snprintk(disc_buf, sizeof(disc_buf), "%s</%u/%u>",
reported ? "," : "",
obj_inst->obj->obj_id, obj_inst->obj_inst_id);
@ -2978,7 +2978,7 @@ static int do_discover_op(struct lwm2m_message *msg, bool well_known)
for (int i = 0; i < obj_inst->resource_count; i++) {
/* skip unrelated resources */
if (msg->path.level == 3 &&
if (msg->path.level == 3U &&
msg->path.res_id != obj_inst->resources[i].res_id) {
continue;
}
@ -3166,9 +3166,9 @@ static int handle_request(struct coap_packet *request,
/* check for .well-known/core URI query (DISCOVER) */
if (r == 2 &&
(options[0].len == 11 &&
(options[0].len == 11U &&
strncmp(options[0].value, ".well-known", 11) == 0) &&
(options[1].len == 4 &&
(options[1].len == 4U &&
strncmp(options[1].value, "core", 4) == 0)) {
if ((code & COAP_REQUEST_MASK) != COAP_METHOD_GET) {
r = -EPERM;
@ -3240,11 +3240,11 @@ static int handle_request(struct coap_packet *request,
break;
case COAP_METHOD_POST:
if (msg->path.level == 1) {
if (msg->path.level == 1U) {
/* create an object instance */
msg->operation = LWM2M_OP_CREATE;
msg->code = COAP_RESPONSE_CODE_CREATED;
} else if (msg->path.level == 2) {
} else if (msg->path.level == 2U) {
/* write values to an object instance */
msg->operation = LWM2M_OP_WRITE;
msg->code = COAP_RESPONSE_CODE_CHANGED;
@ -3756,7 +3756,7 @@ int lwm2m_engine_add_service(k_work_handler_t service, u32_t period_ms)
k_work_init(&service_node_data[i].service_work, service);
service_node_data[i].min_call_period = period_ms;
service_node_data[i].last_timestamp = 0;
service_node_data[i].last_timestamp = 0U;
sys_slist_append(&engine_service_list,
&service_node_data[i].node);
@ -3948,7 +3948,7 @@ static void socket_receive_loop(void)
continue;
}
in_buf[len] = 0;
in_buf[len] = 0U;
lwm2m_udp_receive(sock_ctx[i], in_buf, len, &from_addr,
handle_request);
@ -4077,7 +4077,7 @@ int lwm2m_parse_peerinfo(char *url, struct sockaddr *addr, bool *use_dtls)
/* check for DTLS requirement */
*use_dtls = false;
if (len == 5 && strncmp(url + off, "coaps", len) == 0) {
if (len == 5U && strncmp(url + off, "coaps", len) == 0) {
#if defined(CONFIG_LWM2M_DTLS_SUPPORT)
*use_dtls = true;
#else