mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-26 03:21:44 +03:00
build: silence stupid gcc warning on STREQ_NULLABLE
Our existing STRNEQ_NULLABLE() triggered a warning in gcc 4.7 when used with a literal NULL argument: qemumonitorjsontest.c: In function 'testQemuMonitorJSONGetMachines': qemumonitorjsontest.c:289:5: error: null argument where non-null required (argument 1) [-Werror=nonnull] even though the strcmp is provably dead when a null argument is present. Squelch the warning by refactoring things so that gcc never sees strcmp() called with NULL arguments (we still compare NULL as not equal to "", this rewrite merely aids gcc). Next, gcc has a valid warning about a literal NULLSTR(NULL): qemumonitorjsontest.c:289:5: error: invalid application of 'sizeof' to a void type [-Werror=pointer-arith] Of course, you'd never write NULLSTR(NULL) directly, but it is handy to use through macros. But the entire part about verify_true() is unnecessary - gcc already warns about type mismatch with ?:, without needing to make it more complex. * src/internal.h (STREQ_NULLABLE, STRNEQ_NULLABLE): Avoid gcc 4.7 stupidity. (NULLSTR): Simplify, to allow passing compile-time constants.
This commit is contained in:
parent
7272a92c81
commit
8d8527de32
@ -79,10 +79,9 @@
|
||||
# define STRSKIP(a,b) (STRPREFIX(a,b) ? (a) + strlen(b) : NULL)
|
||||
|
||||
# define STREQ_NULLABLE(a, b) \
|
||||
((!(a) && !(b)) || ((a) && (b) && STREQ((a), (b))))
|
||||
((a) ? (b) && STREQ((a) ? (a) : "", (b) ? (b) : "") : !(b))
|
||||
# define STRNEQ_NULLABLE(a, b) \
|
||||
((!(a) ^ !(b)) || ((a) && (b) && STRNEQ((a), (b))))
|
||||
|
||||
((a) ? !(b) || STRNEQ((a) ? (a) : "", (b) ? (b) : "") : !!(b))
|
||||
|
||||
# define NUL_TERMINATE(buf) do { (buf)[sizeof(buf)-1] = '\0'; } while (0)
|
||||
# define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array)))
|
||||
@ -206,9 +205,7 @@
|
||||
/*
|
||||
* Use this when passing possibly-NULL strings to printf-a-likes.
|
||||
*/
|
||||
# define NULLSTR(s) \
|
||||
((void)verify_true(sizeof(*(s)) == sizeof(char)), \
|
||||
(s) ? (s) : "(null)")
|
||||
# define NULLSTR(s) ((s) ? (s) : "(null)")
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
|
Loading…
Reference in New Issue
Block a user