From bc1d4143ae4dfce3a24485277b4e46a7d0a449f0 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 4 Mar 2017 11:24:37 +0100 Subject: [PATCH] tests: Avoid compiler warning about uses of null_ptr. * tests/null-ptr.h: New file. * tests/test-canonicalize.c: Include null-ptr.h. (null_ptr): Remove function. * tests/test-canonicalize-lgpl.c: Likewise. * tests/test-memmem.c: Likewise. * tests/test-ptsname_r.c: Likewise. * modules/canonicalize-tests (Files): Add tests/null-ptr.h. * modules/canonicalize-lgpl-tests: Likewise. * modules/memmem-tests: Likewise. * modules/ptsname_r-tests: Likewise. Reported by Jim Meyering. --- ChangeLog | 15 +++++++++++++++ modules/canonicalize-lgpl-tests | 1 + modules/canonicalize-tests | 1 + modules/memmem-tests | 3 ++- modules/ptsname_r-tests | 1 + tests/null-ptr.h | 33 +++++++++++++++++++++++++++++++++ tests/test-canonicalize-lgpl.c | 8 ++------ tests/test-canonicalize.c | 8 ++------ tests/test-memmem.c | 7 +------ tests/test-ptsname_r.c | 7 +------ 10 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 tests/null-ptr.h diff --git a/ChangeLog b/ChangeLog index c77d4c849f..e653d82992 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2017-03-04 Bruno Haible + + tests: Avoid compiler warning about uses of null_ptr. + * tests/null-ptr.h: New file. + * tests/test-canonicalize.c: Include null-ptr.h. + (null_ptr): Remove function. + * tests/test-canonicalize-lgpl.c: Likewise. + * tests/test-memmem.c: Likewise. + * tests/test-ptsname_r.c: Likewise. + * modules/canonicalize-tests (Files): Add tests/null-ptr.h. + * modules/canonicalize-lgpl-tests: Likewise. + * modules/memmem-tests: Likewise. + * modules/ptsname_r-tests: Likewise. + Reported by Jim Meyering. + 2017-03-03 Bruno Haible doc: Mention Mac OS X deficiencies regarding semaphores. diff --git a/modules/canonicalize-lgpl-tests b/modules/canonicalize-lgpl-tests index fd49d69e35..22b6b7fade 100644 --- a/modules/canonicalize-lgpl-tests +++ b/modules/canonicalize-lgpl-tests @@ -1,6 +1,7 @@ Files: tests/test-canonicalize-lgpl.c tests/signature.h +tests/null-ptr.h tests/macros.h Depends-on: diff --git a/modules/canonicalize-tests b/modules/canonicalize-tests index 6019349bec..e043a8daca 100644 --- a/modules/canonicalize-tests +++ b/modules/canonicalize-tests @@ -1,5 +1,6 @@ Files: tests/test-canonicalize.c +tests/null-ptr.h tests/macros.h Depends-on: diff --git a/modules/memmem-tests b/modules/memmem-tests index 4738d5c8dd..28c00917a4 100644 --- a/modules/memmem-tests +++ b/modules/memmem-tests @@ -1,7 +1,8 @@ Files: tests/test-memmem.c -tests/zerosize-ptr.h tests/signature.h +tests/null-ptr.h +tests/zerosize-ptr.h tests/macros.h m4/mmap-anon.m4 diff --git a/modules/ptsname_r-tests b/modules/ptsname_r-tests index 50b3f81065..8f7928ebe3 100644 --- a/modules/ptsname_r-tests +++ b/modules/ptsname_r-tests @@ -1,6 +1,7 @@ Files: tests/test-ptsname_r.c tests/signature.h +tests/null-ptr.h tests/macros.h Depends-on: diff --git a/tests/null-ptr.h b/tests/null-ptr.h new file mode 100644 index 0000000000..6743645ad0 --- /dev/null +++ b/tests/null-ptr.h @@ -0,0 +1,33 @@ +/* Return a NULL pointer, without letting the compiler know it. + Copyright (C) 2017 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Return NULL. + Usual compilers are not able to infer something about the return value. */ +static void * +null_ptr (void) +{ + unsigned int x = rand (); + unsigned int y = x * x; + if (y & 2) + return (void *) -1; + else + return (void *) 0; +} + +/* If you want to know why this always returns NULL, read + https://en.wikipedia.org/wiki/Quadratic_residue#Prime_power_modulus . */ diff --git a/tests/test-canonicalize-lgpl.c b/tests/test-canonicalize-lgpl.c index af20a0a215..c449f98937 100644 --- a/tests/test-canonicalize-lgpl.c +++ b/tests/test-canonicalize-lgpl.c @@ -33,16 +33,12 @@ SIGNATURE_CHECK (canonicalize_file_name, char *, (const char *)); #include "same-inode.h" #include "ignore-value.h" + +#include "null-ptr.h" #include "macros.h" #define BASE "t-can-lgpl.tmp" -static void * -null_ptr (void) -{ - return NULL; -} - int main (void) { diff --git a/tests/test-canonicalize.c b/tests/test-canonicalize.c index 0ba89fefd7..37a1126309 100644 --- a/tests/test-canonicalize.c +++ b/tests/test-canonicalize.c @@ -30,16 +30,12 @@ #include "same-inode.h" #include "ignore-value.h" + +#include "null-ptr.h" #include "macros.h" #define BASE "t-can.tmp" -static void * -null_ptr (void) -{ - return NULL; -} - int main (void) { diff --git a/tests/test-memmem.c b/tests/test-memmem.c index bbca811dca..b2c23e6da5 100644 --- a/tests/test-memmem.c +++ b/tests/test-memmem.c @@ -26,15 +26,10 @@ SIGNATURE_CHECK (memmem, void *, (void const *, size_t, void const *, size_t)); #include #include +#include "null-ptr.h" #include "zerosize-ptr.h" #include "macros.h" -static void * -null_ptr (void) -{ - return NULL; -} - int main (int argc, char *argv[]) { diff --git a/tests/test-ptsname_r.c b/tests/test-ptsname_r.c index ed75ce7570..2faf4c74d1 100644 --- a/tests/test-ptsname_r.c +++ b/tests/test-ptsname_r.c @@ -31,6 +31,7 @@ SIGNATURE_CHECK (ptsname_r, int, (int, char *, size_t)); #include "same-inode.h" +#include "null-ptr.h" #include "macros.h" /* Compare two slave names. @@ -53,12 +54,6 @@ same_slave (const char *slave_name1, const char *slave_name2) && SAME_INODE (statbuf1, statbuf2))); } -static char * -null_ptr (void) -{ - return NULL; -} - static void test_errors (int fd, const char *slave) { -- 2.39.5