[Spice-devel] [PATCH spice-server] reds: use a single field for RedsClientMonitorsConfig buffer size

Christophe Fergeau cfergeau at redhat.com
Wed Jun 14 15:29:16 UTC 2017


On Wed, Jun 14, 2017 at 08:54:13AM +0100, Frediano Ziglio wrote:
> 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.

I have a local patch removing RedsClientMonitorsConfig altogether in
favour of SpiceBuffer which would address this as well, but it's on top
of other conflicting patches, I'll try to rebase it and send it as an
alternative to this patch.

Christophe

> 
> 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
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170614/87a5dde7/attachment-0001.sig>


More information about the Spice-devel mailing list