Re: RFC: 'unused return value' errors on RHEL 6

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

 



> 
> 
> spice-bitmap-utils.c has a lot of calls to fwrite() that don't check the
> return value. On RHEL 6 these cause compilation errors due to -Werror:
> 
> spice-bitmap-utils.c:147: error: ignoring return value of 'fwrite',
> declared with attribute warn_unused_result
> 
> What should be done about that?
>  * One option would be to remove -Werror but that would be really
>    heavy handed.
> 
>  * I have not found a way to disable just that one warning. But if
>    others have more luck that could be an option.
> 
>  * The best solution would be to not ignore the return values but that
>    means adding a lot of error-handling code. Does anyone want to take
>    this on?
> 
>  * Otherwise the usual way to trick the compiler is to rewrite the code
>    as
>        (void)(func(...)+1)
>    It's really ugly so it is generally further hidden in a macro.
>    This would yield a patch somewhat like this:
> 
> 
> diff --git a/server/spice-bitmap-utils.c b/server/spice-bitmap-utils.c
> index 8d6e7c6..3cc8b35 100644
> --- a/server/spice-bitmap-utils.c
> +++ b/server/spice-bitmap-utils.c
> @@ -30,6 +30,8 @@
>  #define GRADUAL_HIGH_RGB24_TH -0.03
>  #define GRADUAL_HIGH_RGB16_TH 0
>  
> +#define IGNORE(x) ((void)(x+1))
> +
>  // setting a more permissive threshold for stream identification in order
>  // not to miss streams that were artificially scaled on the guest (e.g.,
>  full screen view
>  // in window media player 12). see red_stream_add_frame
> @@ -141,7 +143,7 @@ static void dump_palette(FILE *f, SpicePalette* plt)
>  {
>      int i;
>      for (i = 0; i < plt->num_ents; i++) {
> -        fwrite(plt->ents + i, sizeof(uint32_t), 1, f);
> +        IGNORE(fwrite(plt->ents + i, sizeof(uint32_t), 1, f));
>      }
>  }
>  
> @@ -150,11 +152,11 @@ static void dump_line(FILE *f, uint8_t* line, uint16_t
> n_pixel_bits, int width,
>      int i;
>      int copy_bytes_size = SPICE_ALIGN(n_pixel_bits * width, 8) / 8;
>  
> -    fwrite(line, 1, copy_bytes_size, f);
> +    IGNORE(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);
> +            IGNORE(fprintf(f, "%c", 0));
>          }
>      }
>  }
> @@ -235,36 +237,36 @@ void dump_bitmap(SpiceBitmap *bitmap)
>      }
>  
>      /* writing the bmp v3 header */
> -    fprintf(f, "BM");
> -    fwrite(&file_size, sizeof(file_size), 1, f);
> +    IGNORE(fprintf(f, "BM"));
> +    IGNORE(fwrite(&file_size, sizeof(file_size), 1, f));
>      tmp_u16 = alpha ? 1 : 0;
> -    fwrite(&tmp_u16, sizeof(tmp_u16), 1, f); // reserved for application
> +    IGNORE(fwrite(&tmp_u16, sizeof(tmp_u16), 1, f)); // reserved for
> application
>      tmp_u16 = 0;
> -    fwrite(&tmp_u16, sizeof(tmp_u16), 1, f);
> -    fwrite(&bitmap_data_offset, sizeof(bitmap_data_offset), 1, f);
> +    IGNORE(fwrite(&tmp_u16, sizeof(tmp_u16), 1, f));
> +    IGNORE(fwrite(&bitmap_data_offset, sizeof(bitmap_data_offset), 1, f));
>      tmp_u32 = header_size - 14;
> -    fwrite(&tmp_u32, sizeof(tmp_u32), 1, f); // sub header size
> +    IGNORE(fwrite(&tmp_u32, sizeof(tmp_u32), 1, f)); // sub header size
>      tmp_32 = bitmap->x;
> -    fwrite(&tmp_32, sizeof(tmp_32), 1, f);
> +    IGNORE(fwrite(&tmp_32, sizeof(tmp_32), 1, f));
>      tmp_32 = bitmap->y;
> -    fwrite(&tmp_32, sizeof(tmp_32), 1, f);
> +    IGNORE(fwrite(&tmp_32, sizeof(tmp_32), 1, f));
>  
>      tmp_u16 = 1;
> -    fwrite(&tmp_u16, sizeof(tmp_u16), 1, f); // color plane
> -    fwrite(&n_pixel_bits, sizeof(n_pixel_bits), 1, f); // pixel depth
> +    IGNORE(fwrite(&tmp_u16, sizeof(tmp_u16), 1, f)); // color plane
> +    IGNORE(fwrite(&n_pixel_bits, sizeof(n_pixel_bits), 1, f)); // pixel
> depth
>  
>      tmp_u32 = 0;
> -    fwrite(&tmp_u32, sizeof(tmp_u32), 1, f); // compression method
> +    IGNORE(fwrite(&tmp_u32, sizeof(tmp_u32), 1, f)); // compression method
>  
>      tmp_u32 = 0; //file_size - bitmap_data_offset;
> -    fwrite(&tmp_u32, sizeof(tmp_u32), 1, f); // image size
> +    IGNORE(fwrite(&tmp_u32, sizeof(tmp_u32), 1, f)); // image size
>      tmp_32 = 0;
> -    fwrite(&tmp_32, sizeof(tmp_32), 1, f);
> -    fwrite(&tmp_32, sizeof(tmp_32), 1, f);
> +    IGNORE(fwrite(&tmp_32, sizeof(tmp_32), 1, f));
> +    IGNORE(fwrite(&tmp_32, sizeof(tmp_32), 1, f));
>      tmp_u32 = (!plt) ? 0 : plt->num_ents; // plt entries
> -    fwrite(&tmp_u32, sizeof(tmp_u32), 1, f);
> +    IGNORE(fwrite(&tmp_u32, sizeof(tmp_u32), 1, f));
>      tmp_u32 = 0;
> -    fwrite(&tmp_u32, sizeof(tmp_u32), 1, f);
> +    IGNORE(fwrite(&tmp_u32, sizeof(tmp_u32), 1, f));
>  
>      if (plt) {
>          dump_palette(f, plt);

Your ignore suggestion with a trick:



diff --git a/server/spice-bitmap-utils.c b/server/spice-bitmap-utils.c
index 8d6e7c6..42c6608 100644
--- a/server/spice-bitmap-utils.c
+++ b/server/spice-bitmap-utils.c
@@ -137,6 +137,15 @@ int spice_bitmap_from_surface_type(uint32_t surface_format)
 
 #define RAM_PATH "/tmp/tmpfs"
 
+static inline void fwrite_noerr(const void *ptr, size_t size, size_t nmemb,
+                                FILE *f)
+{
+    (void)(fwrite(ptr, size, nmemb, f)+1);
+}
+
+#undef fwrite
+#define fwrite(a,b,c,d) fwrite_noerr(a,b,c,d)
+
 static void dump_palette(FILE *f, SpicePalette* plt)
 {
     int i;
@@ -147,17 +156,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);
 }
+
 void dump_bitmap(SpiceBitmap *bitmap)
 {
     static uint32_t file_id = 0;
@@ -235,7 +241,7 @@ void dump_bitmap(SpiceBitmap *bitmap)
     }
 
     /* writing the bmp v3 header */
-    fprintf(f, "BM");
+    fwrite("BM", 2, 1, f);
     fwrite(&file_size, sizeof(file_size), 1, f);
     tmp_u16 = alpha ? 1 : 0;
     fwrite(&tmp_u16, sizeof(tmp_u16), 1, f); // reserved for application



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