[Spice-devel] [PATCH spice-server] stat-file: Use proper macro for container computation

Victor Toso victortoso at redhat.com
Thu Aug 22 07:51:25 UTC 2019


On Thu, Aug 22, 2019 at 08:30:56AM +0100, Frediano Ziglio wrote:
> This is currently more style patch as the "value" field is the
> first field of SpiceStatNode structure, so has offset 0. However
> to compute the containing structure it better to use the proper
> macro to avoid confusion.
> If the offset won't be 0 the subtraction would compute the
> wrong pointer as the offset is expressed in bytes but the
> element size are uint64_t.
> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  server/stat-file.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/server/stat-file.c b/server/stat-file.c
> index 4228be310..38c393389 100644
> --- a/server/stat-file.c
> +++ b/server/stat-file.c
> @@ -233,6 +233,6 @@ void stat_file_remove_node(RedStatFile *stat_file, StatNodeRef ref)
>  
>  void stat_file_remove_counter(RedStatFile *stat_file, uint64_t *counter)
>  {
> -    stat_file_remove(stat_file, (SpiceStatNode *)(counter - SPICE_OFFSETOF(SpiceStatNode, value)));
> +    stat_file_remove(stat_file, SPICE_CONTAINEROF(counter, SpiceStatNode, value));

Sure,
Acked-by: Victor Toso <victortoso at redhat.com>

>  }
>  #endif
> -- 
> 2.20.1
> 
> _______________________________________________
> 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: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20190822/b377f8a2/attachment.sig>


More information about the Spice-devel mailing list