]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
ply-buffer: Fix unused-value warning
authorRay Strode <rstrode@redhat.com>
Thu, 7 Mar 2024 20:09:44 +0000 (15:09 -0500)
committerRay Strode <rstrode@redhat.com>
Thu, 7 Mar 2024 20:14:34 +0000 (15:14 -0500)
We currently get warnings during the build like

```
../src/libply/ply-buffer.h:60:20: warning: value computed is not
used [-Wunused-value]
60 |              !_ran && (*bytes = (char *) ply_buffer_get_bytes(buffer),
   |                    ^~
```

This commit changes the macro to use a GCC statement expression with
an if statement to work around the warning.

Closes: https://gitlab.freedesktop.org/plymouth/plymouth/-/issues/246
src/libply/ply-buffer.h

index 2140e44d529fd625acbfd9cc9ba8af091edc11cf..7b8220a9c1e0d28eeba873ebf20125aa66fd4bd1 100644 (file)
@@ -57,10 +57,14 @@ size_t ply_buffer_get_capacity (ply_buffer_t *buffer);
 char *ply_buffer_steal_bytes (ply_buffer_t *buffer);
 #define ply_buffer_borrow_bytes(buffer, bytes, size, capacity)                 \
         for (bool _ran = false;                                                \
-             !_ran && (*bytes = (char *) ply_buffer_get_bytes (buffer),        \
-                       *size = ply_buffer_get_size (buffer),                   \
-                       *capacity = ply_buffer_get_capacity (buffer)),          \
-             !_ran;                                                            \
+             ({                                                                \
+                      if (!_ran) {                                             \
+                              *bytes = (char *) ply_buffer_get_bytes (buffer); \
+                              *size = ply_buffer_get_size (buffer);            \
+                              *capacity = ply_buffer_get_capacity (buffer);    \
+                      }                                                        \
+                      !_ran;                                                   \
+             });                                                               \
              ply_buffer_set_bytes (buffer, *bytes, *size, *capacity),          \
              _ran = true,                                                      \
              *bytes = NULL,                                                    \