diff mbox

[26/31] vdi: Avoid bitrot of debugging code

Message ID 20170418013356.3578-27-eblake@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Blake April 18, 2017, 1:33 a.m. UTC
Rework the debug define so that we always get -Wformat checking,
even when debugging is disabled.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 block/vdi.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Stefan Weil April 18, 2017, 5:13 a.m. UTC | #1
Am 18.04.2017 um 03:33 schrieb Eric Blake:
> Rework the debug define so that we always get -Wformat checking,
> even when debugging is disabled.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---

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


>  block/vdi.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/block/vdi.c b/block/vdi.c
> index d12d9cd..a70b969 100644
> --- a/block/vdi.c
> +++ b/block/vdi.c
> @@ -86,12 +86,18 @@
>  #define DEFAULT_CLUSTER_SIZE (1 * MiB)
>
>  #if defined(CONFIG_VDI_DEBUG)
> -#define logout(fmt, ...) \
> -                fprintf(stderr, "vdi\t%-24s" fmt, __func__, ##__VA_ARGS__)
> +#define VDI_DEBUG 1
>  #else
> -#define logout(fmt, ...) ((void)0)
> +#define VDI_DEBUG 0
>  #endif
>
> +#define logout(fmt, ...) \
> +    do {                                                                \
> +        if (VDI_DEBUG) {                                                \
> +            fprintf(stderr, "vdi\t%-24s" fmt, __func__, ##__VA_ARGS__); \
> +        }                                                               \
> +    } while (0)
> +
>  /* Image signature. */
>  #define VDI_SIGNATURE 0xbeda107f
>
Philippe Mathieu-Daudé May 13, 2017, 8:35 p.m. UTC | #2
On 04/18/2017 02:13 AM, Stefan Weil wrote:
> Am 18.04.2017 um 03:33 schrieb Eric Blake:
>> Rework the debug define so that we always get -Wformat checking,
>> even when debugging is disabled.
>>
>> Signed-off-by: Eric Blake <eblake@redhat.com>
>> ---
>
> Reviewed-by: Stefan Weil <sw@weilnetz.de>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

>
>>  block/vdi.c | 12 +++++++++---
>>  1 file changed, 9 insertions(+), 3 deletions(-)
>>
>> diff --git a/block/vdi.c b/block/vdi.c
>> index d12d9cd..a70b969 100644
>> --- a/block/vdi.c
>> +++ b/block/vdi.c
>> @@ -86,12 +86,18 @@
>>  #define DEFAULT_CLUSTER_SIZE (1 * MiB)
>>
>>  #if defined(CONFIG_VDI_DEBUG)
>> -#define logout(fmt, ...) \
>> -                fprintf(stderr, "vdi\t%-24s" fmt, __func__,
>> ##__VA_ARGS__)
>> +#define VDI_DEBUG 1
>>  #else
>> -#define logout(fmt, ...) ((void)0)
>> +#define VDI_DEBUG 0
>>  #endif
>>
>> +#define logout(fmt, ...) \
>> +    do
>> {                                                                \
>> +        if (VDI_DEBUG)
>> {                                                \
>> +            fprintf(stderr, "vdi\t%-24s" fmt, __func__,
>> ##__VA_ARGS__); \
>> +
>> }                                                               \
>> +    } while (0)
>> +
>>  /* Image signature. */
>>  #define VDI_SIGNATURE 0xbeda107f
>>
>
>
diff mbox

Patch

diff --git a/block/vdi.c b/block/vdi.c
index d12d9cd..a70b969 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -86,12 +86,18 @@ 
 #define DEFAULT_CLUSTER_SIZE (1 * MiB)

 #if defined(CONFIG_VDI_DEBUG)
-#define logout(fmt, ...) \
-                fprintf(stderr, "vdi\t%-24s" fmt, __func__, ##__VA_ARGS__)
+#define VDI_DEBUG 1
 #else
-#define logout(fmt, ...) ((void)0)
+#define VDI_DEBUG 0
 #endif

+#define logout(fmt, ...) \
+    do {                                                                \
+        if (VDI_DEBUG) {                                                \
+            fprintf(stderr, "vdi\t%-24s" fmt, __func__, ##__VA_ARGS__); \
+        }                                                               \
+    } while (0)
+
 /* Image signature. */
 #define VDI_SIGNATURE 0xbeda107f