Re: [PATCH 1/2] utils: use always fwrite to write bitmap

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2015-12-21 at 11:28 +0000, Frediano Ziglio wrote:
> Make easier to check error on next patch
> ---
>  server/spice-bitmap-utils.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/server/spice-bitmap-utils.c b/server/spice-bitmap-utils.c
> index 8d6e7c6..21d43bf 100644
> --- a/server/spice-bitmap-utils.c
> +++ b/server/spice-bitmap-utils.c
> @@ -147,17 +147,14 @@ 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
> +    fwrite(zeroes, 1, row_size - copy_bytes_size, f);

It seems to me that we should have an assert or something here to ensure that we
don't read off the end of the zeroes array. Something like 

assert(row_size - copy_bytes_size <= 4)

?


>  }
> +
>  void dump_bitmap(SpiceBitmap *bitmap)
>  {
>      static uint32_t file_id = 0;
> @@ -235,7 +232,7 @@ void dump_bitmap(SpiceBitmap *bitmap)
>      }
>  
>      /* writing the bmp v3 header */
> -    fprintf(f, "BM");
> +    fwrite("BM", 2, 1, f);

This doesn't really seem to be a useful intermediate step toward the next patch.
The next patch changes it to put16le() and builds up a full header buffer that
it writes all at once. So I don't think that this hunk helps much.


>      fwrite(&file_size, sizeof(file_size), 1, f);
>      tmp_u16 = alpha ? 1 : 0;
>      fwrite(&tmp_u16, sizeof(tmp_u16), 1, f); // reserved for application
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]