[Spice-devel] [PATCH spice-server] reds: use a single field for RedsClientMonitorsConfig buffer size
Frediano Ziglio
fziglio at redhat.com
Wed Jun 14 07:54:13 UTC 2017
buffer_pos was just the buffer size beside for a short time
during buffer reallocation so just use a field.
Change suggested by Christophe Fergeau.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
server/reds-private.h | 1 -
server/reds.c | 9 ++++-----
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/server/reds-private.h b/server/reds-private.h
index 915bcf6..7e927fe 100644
--- a/server/reds-private.h
+++ b/server/reds-private.h
@@ -64,7 +64,6 @@ typedef struct RedsMigTargetClient {
typedef struct RedsClientMonitorsConfig {
uint8_t *buffer;
int buffer_size;
- int buffer_pos;
} RedsClientMonitorsConfig;
typedef struct ChannelSecurityOptions ChannelSecurityOptions;
diff --git a/server/reds.c b/server/reds.c
index 09b674d..8866c9d 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -1106,7 +1106,7 @@ static void reds_client_monitors_config_cleanup(RedsState *reds)
{
RedsClientMonitorsConfig *cmc = &reds->client_monitors_config;
- cmc->buffer_size = cmc->buffer_pos = 0;
+ cmc->buffer_size = 0;
free(cmc->buffer);
cmc->buffer = NULL;
}
@@ -1118,11 +1118,10 @@ static void reds_on_main_agent_monitors_config(RedsState *reds,
VDAgentMonitorsConfig *monitors_config;
RedsClientMonitorsConfig *cmc = &reds->client_monitors_config;
- cmc->buffer_size += size;
- cmc->buffer = realloc(cmc->buffer, cmc->buffer_size);
+ cmc->buffer = realloc(cmc->buffer, cmc->buffer_size + size);
spice_assert(cmc->buffer);
- memcpy(cmc->buffer + cmc->buffer_pos, message, size);
- cmc->buffer_pos += size;
+ memcpy(cmc->buffer + cmc->buffer_size, message, size);
+ cmc->buffer_size += size;
msg_header = (VDAgentMessage *)cmc->buffer;
if (sizeof(VDAgentMessage) > cmc->buffer_size ||
msg_header->size > cmc->buffer_size - sizeof(VDAgentMessage)) {
--
2.9.4
More information about the Spice-devel
mailing list