[Spice-devel] [PATCH v2 1/2] utils: use always fwrite to write bitmap

Christophe Fergeau cfergeau at redhat.com
Thu Jan 14 09:00:54 PST 2016


On Thu, Jan 14, 2016 at 12:33:06PM +0000, Frediano Ziglio wrote:
> Make easier to check error on next patch
> ---
>  server/spice-bitmap-utils.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/server/spice-bitmap-utils.c b/server/spice-bitmap-utils.c
> index 8d6e7c6..e6be15f 100644
> --- a/server/spice-bitmap-utils.c
> +++ b/server/spice-bitmap-utils.c
> @@ -147,17 +147,15 @@ static void dump_palette(FILE *f, SpicePalette* plt)
>  
>  static void dump_line(FILE *f, uint8_t* line, uint16_t n_pixel_bits, int width, int row_size)
>  {
> -    int i;
> +    static char zeroes[4] = { 0 };
>      int copy_bytes_size = SPICE_ALIGN(n_pixel_bits * width, 8) / 8;
>  
>      fwrite(line, 1, copy_bytes_size, f);
> -    if (row_size > copy_bytes_size) {
> -        // each line should be 4 bytes aligned
> -        for (i = copy_bytes_size; i < row_size; i++) {
> -            fprintf(f, "%c", 0);
> -        }
> -    }
> +    // each line should be 4 bytes aligned
> +    spice_assert(row_size - copy_bytes_size >= 0 && row_size - copy_bytes_size <= 4);

I'd prefer g_return_if_fail() here.

Acked-by: Christophe Fergeau <cfergeau at redhat.com>

> +    fwrite(zeroes, 1, row_size - copy_bytes_size, f);
>  }
> +
>  void dump_bitmap(SpiceBitmap *bitmap)
>  {
>      static uint32_t file_id = 0;
> -- 
> 2.4.3
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20160114/3d740c5c/attachment.sig>


More information about the Spice-devel mailing list