From 2af29378bfc5f63f3fa8a9e59b96be5b90ed6fd4 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Sun, 22 Jan 2023 17:03:30 +0200 Subject: [PATCH] prevent unneeded memset --- Makefile | 2 +- server.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 00a1291..32dc177 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC?=gcc CFLAGS_DEV=-DJB_PRESET_DEBUG -ggdb -fsanitize=address -Og -CFLAGS_RELEASE=-O2 -fgraphite-identity -funroll-loops -ftree-vectorize -flto +CFLAGS_RELEASE=-O2 -fgraphite-identity -funroll-loops -ftree-vectorize -flto -ggdb CFLAGS+=-pipe -Wall -Wextra -Wshadow -pedantic -std=c99 diff --git a/server.c b/server.c index e466ee2..269c824 100644 --- a/server.c +++ b/server.c @@ -379,7 +379,7 @@ int bus_broadcast_signal(Bus *s, BusClient *client, WireCtx *ctx, WireMsg *msg) return 0; } -int bus_unicast_message(Bus *s, WireMsg *msg, WireCtx *ctx, char *target_name, char *sender_unique_name, WireCtx *reply_ctx) +int bus_unicast_message(Bus *s, WireMsg *msg, WireCtx *ctx, char *target_name, char *sender_unique_name) { BusClient *target = TRYPTR(bus_name_find_client(s, target_name)); struct iovec bufs[2] = {0}; @@ -765,7 +765,7 @@ int bus_client_process_message(Bus *s, BusClient *client, WireCtx *ctx) } if (destination_field->present) { - if (bus_unicast_message(s, &msg, ctx, destination_field->t.str, client->unique_name->name, &reply_ctx) < 0) { + if (bus_unicast_message(s, &msg, ctx, destination_field->t.str, client->unique_name->name) < 0) { _process_message_reply_error("xyz.hippoz.jitterbug.UnicastFailed"); goto end_nonfatal; } @@ -823,7 +823,7 @@ int bus_client_drain_messages(Bus *s, BusClient *client, uint8_t *data, uint32_t return 0; } -#define _client_die(m) do { bus_client_error(s, &s->clients[i], m); goto done; } while(0) +#define _client_die(m) do { bus_client_error(s, &s->clients[i], m); continue; } while(0) int bus_turn(Bus *s) { static const char agree_unix_fd[] = "ERROR\r\n"; @@ -880,6 +880,11 @@ int bus_turn(Bus *s) bus_client_remove(s, &s->clients[i]); continue; } + if (unlikely(bytes + 1 >= data_buffer_len)) { + continue; + } + + data[bytes] = '\0'; VERBOSE("\nrecv: got %zd bytes\n", bytes); @@ -941,9 +946,6 @@ int bus_turn(Bus *s) _client_die("bad state"); } break; } - -done: - memset(data, 0, bytes); } }