[PATCH] Get rid of warning comparision will always evaluate as true
Stefan Liebler
stli@linux.vnet.ibm.com
Thu Dec 11 08:20:00 GMT 2014
Hi,
i get the following warning/error while running make xcheck:
gcc tst-mutexpp6.c -c ...
In file included from tst-mutexpp6.c:45:0:
tst-mutex6.c: In function âdo_testâ:
tst-mutex6.c:38:12: error: the comparison will always evaluate as âtrueâ
for the address of âaâ will never be NULL [-Werror=address]
if (ATTR != NULL && e == ENOTSUP)
^
tst-mutex6.c:49:12: error: the comparison will always evaluate as âtrueâ
for the address of âaâ will never be NULL [-Werror=address]
if (ATTR != NULL && pthread_mutexattr_destroy (ATTR) != 0)
^
cc1: all warnings being treated as errors
In tst-mutexpp6.c ATTR is defined to "a", which is static
pthread_mutexattr_t and can´t be NULL.
Thus ATTR_NULL is introduced like in tst-mutex1.c,
which is set to false in tst-mutexpp6.c to avoid the warning
and checks ATTR against NULL in the other cases.
Ok to commit?
Bye Stefan
---
2014-12-11 Stefan Liebler <stli@linux.vnet.ibm.com>
nptl/tst-mutex6.c
(ATTR_NULL): New define checks ATTR against NULL.
(do_test): Use !ATTR_NULL instead of ATTR != NULL.
nptl/tst-mutexpp6.c (ATTR_NULL): New define.
-------------- next part --------------
diff --git a/nptl/tst-mutex6.c b/nptl/tst-mutex6.c
index 292e3bf..9c11a20 100644
--- a/nptl/tst-mutex6.c
+++ b/nptl/tst-mutex6.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
+#include <stdbool.h>
#ifndef ATTR
@@ -28,6 +29,9 @@ pthread_mutexattr_t *attr;
# define ATTR attr
#endif
+#ifndef ATTR_NULL
+# define ATTR_NULL (ATTR == NULL)
+#endif
static int
do_test (void)
@@ -35,7 +39,7 @@ do_test (void)
pthread_mutex_t m;
int e = pthread_mutex_init (&m, ATTR);
- if (ATTR != NULL && e == ENOTSUP)
+ if (!ATTR_NULL && e == ENOTSUP)
{
puts ("cannot support selected type of mutexes");
e = pthread_mutex_init (&m, NULL);
@@ -46,7 +50,7 @@ do_test (void)
return 1;
}
- if (ATTR != NULL && pthread_mutexattr_destroy (ATTR) != 0)
+ if (!ATTR_NULL && pthread_mutexattr_destroy (ATTR) != 0)
{
puts ("mutexattr_destroy failed");
return 1;
diff --git a/nptl/tst-mutexpp6.c b/nptl/tst-mutexpp6.c
index 2ddf6b4..87a6ebd 100644
--- a/nptl/tst-mutexpp6.c
+++ b/nptl/tst-mutexpp6.c
@@ -42,4 +42,5 @@ do_test_wrapper (void)
#define TEST_FUNCTION do_test_wrapper ()
#define ATTR &a
+#define ATTR_NULL false
#include "tst-mutex6.c"
More information about the Libc-alpha
mailing list