mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-09 10:32:53 +03:00
Windows C4267 errors: Fix size_t conversion warnings in windows builds
examples/client.c: examples/coap-rd.c: examples/coap-server.c: include/coap2/block.h: include/coap2/coap_hashkey.h: src/block.c: src/coap_debug.c: src/coap_hashkey.c: src/coap_io.c: src/coap_openssl.c: src/net.c: Fix C4267 windows compilation warnings when using Visual Studio where size_t variable parameters are being converted in both size and sign. There still are some C4116 warnings to fix.
This commit is contained in:
1 parent
636a4df2b5
commit
bb38e995bc
11 files changed
+34
-32
No files matched your search
+6
-6
@@ -194,7 +194,7 @@ coap_new_request(coap_context_t *ctx,
|
||||
unsigned char buf[4];
|
||||
coap_add_option(pdu,
|
||||
COAP_OPTION_SIZE1,
|
||||
coap_encode_var_safe(buf, sizeof(buf), length),
|
||||
coap_encode_var_safe8(buf, sizeof(buf), length),
|
||||
buf);
|
||||
|
||||
coap_add_block(pdu, length, data, block.num, block.szx);
|
||||
@@ -314,7 +314,7 @@ resolve_address(const coap_str_const_t *server, struct sockaddr *dst) {
|
||||
switch (ainfo->ai_family) {
|
||||
case AF_INET6:
|
||||
case AF_INET:
|
||||
len = ainfo->ai_addrlen;
|
||||
len = (int)ainfo->ai_addrlen;
|
||||
memcpy(dst, ainfo->ai_addr, len);
|
||||
goto finish;
|
||||
default:
|
||||
@@ -572,7 +572,7 @@ message_handler(struct coap_context_t *ctx,
|
||||
|
||||
coap_add_option(pdu,
|
||||
COAP_OPTION_SIZE1,
|
||||
coap_encode_var_safe(buf, sizeof(buf), payload.length),
|
||||
coap_encode_var_safe8(buf, sizeof(buf), payload.length),
|
||||
buf);
|
||||
|
||||
coap_add_block(pdu,
|
||||
@@ -906,7 +906,7 @@ set_blocksize(void) {
|
||||
opt = method == COAP_REQUEST_GET ? COAP_OPTION_BLOCK2 : COAP_OPTION_BLOCK1;
|
||||
|
||||
block.m = (opt == COAP_OPTION_BLOCK1) &&
|
||||
((1u << (block.szx + 4)) < payload.length);
|
||||
((1ull << (block.szx + 4)) < payload.length);
|
||||
|
||||
opt_length = coap_encode_var_safe(buf, sizeof(buf),
|
||||
(block.num << 4 | block.m << 3 | block.szx));
|
||||
@@ -1078,7 +1078,7 @@ decode_segment(const uint8_t *seg, size_t length, unsigned char *buf) {
|
||||
static int
|
||||
check_segment(const uint8_t *s, size_t length) {
|
||||
|
||||
size_t n = 0;
|
||||
int n = 0;
|
||||
|
||||
while (length) {
|
||||
if (*s == '%') {
|
||||
@@ -1458,7 +1458,7 @@ get_session(
|
||||
coap_address_t bind_addr;
|
||||
if ( rp->ai_addrlen <= sizeof( bind_addr.addr ) ) {
|
||||
coap_address_init( &bind_addr );
|
||||
bind_addr.size = rp->ai_addrlen;
|
||||
bind_addr.size = (socklen_t)rp->ai_addrlen;
|
||||
memcpy( &bind_addr.addr, rp->ai_addr, rp->ai_addrlen );
|
||||
session = open_session(ctx, proto, &bind_addr, dst,
|
||||
identity, identity_len, key, key_len);
|
||||
|
||||
+1
-1
@@ -723,7 +723,7 @@ get_context(const char *node, const char *port) {
|
||||
|
||||
if (rp->ai_addrlen <= sizeof(addr.addr)) {
|
||||
coap_address_init(&addr);
|
||||
addr.size = rp->ai_addrlen;
|
||||
addr.size = (socklen_t)rp->ai_addrlen;
|
||||
memcpy(&addr.addr, rp->ai_addr, rp->ai_addrlen);
|
||||
addrs = addr;
|
||||
if (addr.addr.sa.sa_family == AF_INET) {
|
||||
|
||||
@@ -35,6 +35,8 @@ static char* strndup(const char* s1, size_t n)
|
||||
}
|
||||
return copy;
|
||||
};
|
||||
#include <io.h>
|
||||
#define access _access
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/select.h>
|
||||
@@ -320,10 +322,11 @@ check_async(coap_context_t *ctx,
|
||||
coap_tick_t now) {
|
||||
coap_pdu_t *response;
|
||||
coap_async_state_t *tmp;
|
||||
async_data_t data = { .ptr = async ? async->appdata : NULL };
|
||||
|
||||
size_t size = 13;
|
||||
|
||||
if (!async || now < async->created + (unsigned long)async->appdata)
|
||||
if (!async || now < async->created + data.val)
|
||||
return;
|
||||
|
||||
response = coap_pdu_init(async->flags & COAP_ASYNC_CONFIRM
|
||||
@@ -332,7 +335,6 @@ check_async(coap_context_t *ctx,
|
||||
COAP_RESPONSE_CODE(205), 0, size);
|
||||
if (!response) {
|
||||
coap_log(LOG_DEBUG, "check_async: insufficient memory, we'll try later\n");
|
||||
async_data_t data = { .ptr = async->appdata };
|
||||
data.val = data.val + 15 * COAP_TICKS_PER_SECOND;
|
||||
async->appdata = data.ptr;
|
||||
return;
|
||||
@@ -1075,7 +1077,7 @@ get_context(const char *node, const char *port) {
|
||||
|
||||
if (rp->ai_addrlen <= sizeof(addr.addr)) {
|
||||
coap_address_init(&addr);
|
||||
addr.size = rp->ai_addrlen;
|
||||
addr.size = (socklen_t)rp->ai_addrlen;
|
||||
memcpy(&addr.addr, rp->ai_addr, rp->ai_addrlen);
|
||||
addrs = addr;
|
||||
if (addr.addr.sa.sa_family == AF_INET) {
|
||||
|
||||
Reference in new issue
Block a user