diff mbox series

[3/3] libvhost-user: Add format attribute to local function vu_panic

Message ID 20220422070144.1043697-4-sw@weilnetz.de
State New
Headers show
Series libvhost-user: Add format attribute and fix format strings | expand

Commit Message

Stefan Weil April 22, 2022, 7:01 a.m. UTC
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---

It would be good to add format attributes to local functions, too (like
it is done here) to avoid future format bugs.

The changes here could be simplified by including a glib header,
but from the comments I assumed that is unwanted here?

 subprojects/libvhost-user/libvhost-user.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Marc-André Lureau April 22, 2022, 9:35 a.m. UTC | #1
Hi

On Fri, Apr 22, 2022 at 11:08 AM Stefan Weil <sw@weilnetz.de> wrote:

> Signed-off-by: Stefan Weil <sw@weilnetz.de>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>



> ---
>
> It would be good to add format attributes to local functions, too (like
> it is done here) to avoid future format bugs.
>
> The changes here could be simplified by including a glib header,
> but from the comments I assumed that is unwanted here?
>

For historical reasons, libvhost-user.c doesn't depend on glib. Whether
this is useful to anyone isn't obvious :)


>  subprojects/libvhost-user/libvhost-user.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/subprojects/libvhost-user/libvhost-user.c
> b/subprojects/libvhost-user/libvhost-user.c
> index 94645f9154..29ab85fc9d 100644
> --- a/subprojects/libvhost-user/libvhost-user.c
> +++ b/subprojects/libvhost-user/libvhost-user.c
> @@ -45,6 +45,17 @@
>  #include "libvhost-user.h"
>
>  /* usually provided by GLib */
> +#if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
> +#if !defined(__clang__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 4)
> +#define G_GNUC_PRINTF(format_idx, arg_idx) \
> +  __attribute__((__format__(gnu_printf, format_idx, arg_idx)))
> +#else
> +#define G_GNUC_PRINTF(format_idx, arg_idx) \
> +  __attribute__((__format__(__printf__, format_idx, arg_idx)))
> +#endif
> +#else   /* !__GNUC__ */
> +#define G_GNUC_PRINTF(format_idx, arg_idx)
> +#endif  /* !__GNUC__ */
>  #ifndef MIN
>  #define MIN(x, y) ({                            \
>              typeof(x) _min1 = (x);              \
> @@ -151,7 +162,7 @@ vu_request_to_string(unsigned int req)
>      }
>  }
>
> -static void
> +static void G_GNUC_PRINTF(2, 3)
>  vu_panic(VuDev *dev, const char *msg, ...)
>  {
>      char *buf = NULL;
> --
> 2.30.2
>
>
>
Laurent Vivier Nov. 2, 2022, 6:24 p.m. UTC | #2
Le 22/04/2022 à 09:01, Stefan Weil a écrit :
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
> 
> It would be good to add format attributes to local functions, too (like
> it is done here) to avoid future format bugs.
> 
> The changes here could be simplified by including a glib header,
> but from the comments I assumed that is unwanted here?
> 
>   subprojects/libvhost-user/libvhost-user.c | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c
> index 94645f9154..29ab85fc9d 100644
> --- a/subprojects/libvhost-user/libvhost-user.c
> +++ b/subprojects/libvhost-user/libvhost-user.c
> @@ -45,6 +45,17 @@
>   #include "libvhost-user.h"
>   
>   /* usually provided by GLib */
> +#if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
> +#if !defined(__clang__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 4)
> +#define G_GNUC_PRINTF(format_idx, arg_idx) \
> +  __attribute__((__format__(gnu_printf, format_idx, arg_idx)))
> +#else
> +#define G_GNUC_PRINTF(format_idx, arg_idx) \
> +  __attribute__((__format__(__printf__, format_idx, arg_idx)))
> +#endif
> +#else   /* !__GNUC__ */
> +#define G_GNUC_PRINTF(format_idx, arg_idx)
> +#endif  /* !__GNUC__ */
>   #ifndef MIN
>   #define MIN(x, y) ({                            \
>               typeof(x) _min1 = (x);              \
> @@ -151,7 +162,7 @@ vu_request_to_string(unsigned int req)
>       }
>   }
>   
> -static void
> +static void G_GNUC_PRINTF(2, 3)
>   vu_panic(VuDev *dev, const char *msg, ...)
>   {
>       char *buf = NULL;

Applied to my trivial-patches branch.

Thanks,
Laurent
diff mbox series

Patch

diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c
index 94645f9154..29ab85fc9d 100644
--- a/subprojects/libvhost-user/libvhost-user.c
+++ b/subprojects/libvhost-user/libvhost-user.c
@@ -45,6 +45,17 @@ 
 #include "libvhost-user.h"
 
 /* usually provided by GLib */
+#if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
+#if !defined(__clang__) && (__GNUC__ == 4 && __GNUC_MINOR__ == 4)
+#define G_GNUC_PRINTF(format_idx, arg_idx) \
+  __attribute__((__format__(gnu_printf, format_idx, arg_idx)))
+#else
+#define G_GNUC_PRINTF(format_idx, arg_idx) \
+  __attribute__((__format__(__printf__, format_idx, arg_idx)))
+#endif
+#else   /* !__GNUC__ */
+#define G_GNUC_PRINTF(format_idx, arg_idx)
+#endif  /* !__GNUC__ */
 #ifndef MIN
 #define MIN(x, y) ({                            \
             typeof(x) _min1 = (x);              \
@@ -151,7 +162,7 @@  vu_request_to_string(unsigned int req)
     }
 }
 
-static void
+static void G_GNUC_PRINTF(2, 3)
 vu_panic(VuDev *dev, const char *msg, ...)
 {
     char *buf = NULL;