Re: [PATCH 2/2] utils: fix endianess issues writing bitmap file and handle errors

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

 



On 12/23/2015 06:42 PM, Jonathon Jongsma wrote:
On Mon, 2015-12-21 at 11:28 +0000, Frediano Ziglio wrote:
Do not print directly binary data but serialize in a portable way
and then use write functions.
Also handle errors writing to file.
---
  server/spice-bitmap-utils.c | 106 +++++++++++++++++++++++++++----------------
-
  1 file changed, 66 insertions(+), 40 deletions(-)

diff --git a/server/spice-bitmap-utils.c b/server/spice-bitmap-utils.c
index 21d43bf..559b0de 100644
--- a/server/spice-bitmap-utils.c
+++ b/server/spice-bitmap-utils.c
@@ -137,22 +137,51 @@ int spice_bitmap_from_surface_type(uint32_t
surface_format)

  #define RAM_PATH "/tmp/tmpfs"

-static void dump_palette(FILE *f, SpicePalette* plt)
+static void put_16le(uint8_t **ptr, uint16_t val)
+{
+    **ptr = val & 0xffu;
+    (*ptr)++;
+    val >>= 8;
+    **ptr = val & 0xffu;
+    (*ptr)++;
+}
+
+static void put_32le(uint8_t **ptr, uint32_t val)
+{
+    put_16le(ptr, val & 0xffffu);
+    val >>= 16;
+    put_16le(ptr, val & 0xffffu);
+}
+
+#define write(buf, size) do { \
+    if (fwrite(buf, 1, (size), f) != (size)) \
+        goto write_err; \
+} while(0)

I'd personally prefer that the FILE pointer was an argument to the macro and we
didn't assume a variable named 'f'.


Also I prefer to rename the macro to not
shadow the write function.


_______________________________________________
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]