From 68f4ae12c8b4887b60fb0f3d6a48780588acecac Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sun, 10 May 2026 18:56:06 +0300 Subject: [PATCH] fix all compiler warnings: array-bool, pointer-sign, tautological, unsequenced --- src/config_updater.c | 8 ++++---- src/etcp_api.c | 19 ++++++++----------- src/etcp_connections.c | 7 +++---- src/etcp_loadbalancer.c | 2 +- src/etcp_router.c | 6 ++---- src/secure_channel.c | 10 +++++----- src/secure_channel.h | 2 +- src/utun_instance.c | 2 +- 8 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/config_updater.c b/src/config_updater.c index 5fc6799c..2f21bca9 100644 --- a/src/config_updater.c +++ b/src/config_updater.c @@ -257,10 +257,10 @@ int config_ensure_keys_and_node_id(const char *filename) { // Debug: print what we found DEBUG_DEBUG(DEBUG_CATEGORY_CONFIG, "Checking config - priv_key='%s' (len=%zu), pub_key='%s' (len=%zu), node_id=%016llx", - global->my_private_key_hex ? global->my_private_key_hex : "NULL", - global->my_private_key_hex ? strlen(global->my_private_key_hex) : 0, - global->my_public_key_hex ? global->my_public_key_hex : "NULL", - global->my_public_key_hex ? strlen(global->my_public_key_hex) : 0, + global->my_private_key_hex[0] ? global->my_private_key_hex : "NULL", + global->my_private_key_hex[0] ? strlen(global->my_private_key_hex) : 0, + global->my_public_key_hex[0] ? global->my_public_key_hex : "NULL", + global->my_public_key_hex[0] ? strlen(global->my_public_key_hex) : 0, (unsigned long long)global->my_node_id); diff --git a/src/etcp_api.c b/src/etcp_api.c index 02c925b3..a562bc52 100644 --- a/src/etcp_api.c +++ b/src/etcp_api.c @@ -57,24 +57,21 @@ int etcp_bind(struct UTUN_INSTANCE* inst, uint8_t id, etcp_recv_fn callback) { return -1; } - if (id >= ETCP_MAX_BINDINGS) { + if ((unsigned)id >= ETCP_MAX_BINDINGS) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP_API, "etcp_bind: Invalid ID %u (max=%d)", id, ETCP_MAX_BINDINGS); return -1; } - + if (!callback) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP_API, "etcp_bind: NULL callback for id=%u", id); return -1; } - + if (inst->api_bindings.callbacks[id] != NULL) { - DEBUG_WARN(DEBUG_CATEGORY_ETCP_API, "etcp_bind: ID %u already bound, overwriting", id); + DEBUG_WARN(DEBUG_CATEGORY_ETCP_API, "etcp_bind: Overwriting existing callback for id=%u", id); } - inst->api_bindings.callbacks[id] = callback; - - DEBUG_INFO(DEBUG_CATEGORY_ETCP_API, "etcp_bind: Bound ID %u to callback %p for instance %p", - id, (void*)callback, (void*)inst); + DEBUG_INFO(DEBUG_CATEGORY_ETCP_API, "etcp_bind: Bound id=%u → callback=%p", id, (void*)callback); return 0; } @@ -83,8 +80,8 @@ int etcp_unbind(struct UTUN_INSTANCE* inst, uint8_t id) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP_API, "etcp_unbind: NULL instance"); return -1; } - - if (id >= ETCP_MAX_BINDINGS) { + + if ((unsigned)id >= ETCP_MAX_BINDINGS) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP_API, "etcp_unbind: Invalid ID %u", id); return -1; } @@ -177,7 +174,7 @@ void etcp_int_recv(struct ll_queue* queue, void* arg) { } // Ищем binding для этого ID в instance - if (id < ETCP_MAX_BINDINGS && inst->api_bindings.callbacks[id] != NULL) { + if (inst->api_bindings.callbacks[id] != NULL) { // Вызываем коллбэк DEBUG_DEBUG(DEBUG_CATEGORY_ETCP_API, "etcp_recv: Delivering packet ID %u to callback %p", id, (void*)inst->api_bindings.callbacks[id]); diff --git a/src/etcp_connections.c b/src/etcp_connections.c index 42deccc0..367f7166 100644 --- a/src/etcp_connections.c +++ b/src/etcp_connections.c @@ -478,9 +478,7 @@ int etcp_find_free_local_link_id(struct ETCP_CONN* etcp) { // Помечаем занятые id struct ETCP_LINK* link = etcp->links; while (link) { - if (link->local_link_id < 256) { - used_ids[link->local_link_id >> 3] |= (1 << (link->local_link_id & 7)); - } + used_ids[link->local_link_id >> 3] |= (1 << (link->local_link_id & 7)); link = link->next; } @@ -1774,7 +1772,8 @@ process_decrypted: memory_pool_free(e_sock->instance->pkt_pool, pkt); return; } - link->mtu_remote = (pkt->data[offset++] << 8) | pkt->data[offset++]; + link->mtu_remote = ((uint16_t)pkt->data[offset] << 8) | pkt->data[offset + 1]; + offset += 2; if (link->mtu_remote > PACKET_DATA_MAX_MTU) link->mtu_remote = PACKET_DATA_MAX_MTU; link->mtu = link->mtu_local < link->mtu_remote ? link->mtu_local : link->mtu_remote; link->remote_link_id = pkt->data[offset++]; diff --git a/src/etcp_loadbalancer.c b/src/etcp_loadbalancer.c index 0f91da72..40ca7cf6 100644 --- a/src/etcp_loadbalancer.c +++ b/src/etcp_loadbalancer.c @@ -232,7 +232,7 @@ int etcp_loadbalancer_get_link_status(struct ETCP_CONN* etcp) { } DEBUG_TRACE(DEBUG_CATEGORY_ETCP, "[%s] link status check: %d alive links", - etcp->log_name ? etcp->log_name : "????→????", alive_count); + etcp->log_name[0] ? etcp->log_name : "????→????", alive_count); return (alive_count > 0) ? 1 : 0; } diff --git a/src/etcp_router.c b/src/etcp_router.c index c23ea80e..ea00c652 100644 --- a/src/etcp_router.c +++ b/src/etcp_router.c @@ -25,7 +25,7 @@ static void etcp_router_recv_cb(struct ETCP_CONN* conn, struct ll_entry* entry) uint8_t svc_id = entry->dgram[1]; uint64_t dst_node_id = 0; memcpy(&dst_node_id, entry->dgram + 2, 8); if (dst_node_id == inst->node_id) { - if (svc_id >= SVC_ROUTE_MAX_BINDINGS || !inst->router_bindings.callbacks[svc_id]) { + if (!inst->router_bindings.callbacks[svc_id]) { DEBUG_WARN(DEBUG_CATEGORY_ETCP, "etcp_router: no handler for svc_id=%u dst=%016llx self=%016llx", svc_id, (unsigned long long)dst_node_id, (unsigned long long)inst->node_id); queue_entry_free(entry); queue_dgram_free(entry); @@ -80,7 +80,6 @@ void etcp_router_destroy(struct UTUN_INSTANCE* inst) { int etcp_router_bind(struct UTUN_INSTANCE* inst, uint8_t svc_id, etcp_recv_fn callback) { if (!inst) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "etcp_router_bind: NULL instance"); return -1; } - if (svc_id >= SVC_ROUTE_MAX_BINDINGS) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "etcp_router_bind: invalid svc_id %u", svc_id); return -1; } if (!callback) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "etcp_router_bind: NULL callback for svc_id=%u", svc_id); return -1; } if (inst->router_bindings.callbacks[svc_id]) DEBUG_WARN(DEBUG_CATEGORY_ETCP, "etcp_router_bind: overwriting svc_id=%u", svc_id); inst->router_bindings.callbacks[svc_id] = callback; @@ -90,7 +89,6 @@ int etcp_router_bind(struct UTUN_INSTANCE* inst, uint8_t svc_id, etcp_recv_fn ca int etcp_router_unbind(struct UTUN_INSTANCE* inst, uint8_t svc_id) { if (!inst) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "etcp_router_unbind: NULL instance"); return -1; } - if (svc_id >= SVC_ROUTE_MAX_BINDINGS) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "etcp_router_unbind: invalid svc_id %u", svc_id); return -1; } if (!inst->router_bindings.callbacks[svc_id]) { DEBUG_WARN(DEBUG_CATEGORY_ETCP, "etcp_router_unbind: svc_id=%u not bound", svc_id); return -1; } inst->router_bindings.callbacks[svc_id] = NULL; DEBUG_INFO(DEBUG_CATEGORY_ETCP, "etcp_router_unbind: svc_id=%u", svc_id); @@ -114,7 +112,7 @@ int etcp_route_send(struct UTUN_INSTANCE* inst, uint64_t dst_node_id, struct ll_ // Loopback — dispatch прямо локально if (dst_node_id == inst->node_id) { DEBUG_TRACE(DEBUG_CATEGORY_ETCP, "etcp_route_send: loopback svc_id=%u len=%zu", svc_id, payload_len); - if (svc_id < SVC_ROUTE_MAX_BINDINGS && inst->router_bindings.callbacks[svc_id]) + if (inst->router_bindings.callbacks[svc_id]) inst->router_bindings.callbacks[svc_id](NULL, entry); else { queue_entry_free(entry); queue_dgram_free(entry); } return 0; diff --git a/src/secure_channel.c b/src/secure_channel.c index 53243b6d..95ae0128 100644 --- a/src/secure_channel.c +++ b/src/secure_channel.c @@ -256,15 +256,15 @@ sc_status_t sc_init_local_keys(struct SC_MYKEYS *mykeys, const char *public_key, return SC_OK; } -sc_status_t sc_set_peer_public_key(sc_context_t *ctx, const char *peer_public_key_h, int mode) { +sc_status_t sc_set_peer_public_key(sc_context_t *ctx, const uint8_t *peer_public_key_h, int mode) { uint8_t peer_public_key[SC_PUBKEY_SIZE]; if (mode) { - if (hex_to_binary(peer_public_key_h, peer_public_key, SC_PUBKEY_SIZE)) { + if (hex_to_binary((const char*)peer_public_key_h, peer_public_key, SC_PUBKEY_SIZE)) { DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "sc_set_peer_public_key: invalid hex key format"); return SC_ERR_INVALID_ARG; } } else { - memcpy(peer_public_key, (const uint8_t *)peer_public_key_h, SC_PUBKEY_SIZE); + memcpy(peer_public_key, peer_public_key_h, SC_PUBKEY_SIZE); } if (!ctx) { DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "sc_set_peer_public_key: invalid ctx"); @@ -616,12 +616,12 @@ sc_status_t sc_init_local_keys(struct SC_MYKEYS *mykeys, const char *public_key, return SC_OK; } -sc_status_t sc_set_peer_public_key(sc_context_t *ctx, const char *peer_public_key_h, int mode) { +sc_status_t sc_set_peer_public_key(sc_context_t *ctx, const uint8_t *peer_public_key_h, int mode) { uint8_t shared_secret[SC_SHARED_SECRET_SIZE]; uint8_t peer_public_key[SC_PUBKEY_SIZE]; if (mode) { - if (hex_to_binary(peer_public_key_h, peer_public_key, SC_PUBKEY_SIZE)) { + if (hex_to_binary((const char*)peer_public_key_h, peer_public_key, SC_PUBKEY_SIZE)) { DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "sc_set_peer_public_key: invalid hex key format"); return SC_ERR_INVALID_ARG; } diff --git a/src/secure_channel.h b/src/secure_channel.h index e3189c77..165a705d 100644 --- a/src/secure_channel.h +++ b/src/secure_channel.h @@ -62,7 +62,7 @@ struct secure_channel { sc_status_t sc_init_ctx(sc_context_t *ctx, struct SC_MYKEYS *mykeys); sc_status_t sc_generate_keypair(struct SC_MYKEYS *keys); sc_status_t sc_init_local_keys(struct SC_MYKEYS *mykeys, const char *public_key, const char *private_key); -sc_status_t sc_set_peer_public_key(sc_context_t *ctx, const char *peer_public_key, int mode);// mode: 0-bin 1-hex key format +sc_status_t sc_set_peer_public_key(sc_context_t *ctx, const uint8_t *peer_public_key, int mode);// mode: 0-bin 1-hex key format sc_status_t sc_compute_public_key_from_private(const uint8_t *private_key, uint8_t *public_key); // Криптографические операции diff --git a/src/utun_instance.c b/src/utun_instance.c index 6a5b6807..48b53c58 100644 --- a/src/utun_instance.c +++ b/src/utun_instance.c @@ -186,7 +186,7 @@ struct UTUN_INSTANCE* utun_instance_create(struct UASYNC* ua, const char *config } // Open log file only if not using global debug system output - if (config->global.log_file) { + if (config->global.log_file[0]) { debug_set_output_file(config->global.log_file); }