]> Savannah Git Hosting - gnulib.git/commitdiff
tests: Avoid compiler warning about uses of null_ptr.
authorBruno Haible <bruno@clisp.org>
Sat, 4 Mar 2017 10:24:37 +0000 (11:24 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 4 Mar 2017 10:25:20 +0000 (11:25 +0100)
* 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
modules/canonicalize-lgpl-tests
modules/canonicalize-tests
modules/memmem-tests
modules/ptsname_r-tests
tests/null-ptr.h [new file with mode: 0644]
tests/test-canonicalize-lgpl.c
tests/test-canonicalize.c
tests/test-memmem.c
tests/test-ptsname_r.c

index c77d4c849fc592a92f5cb0e347dccffa0b54c3a3..e653d82992a0e593694106150751277e380dedeb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2017-03-04  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        doc: Mention Mac OS X deficiencies regarding semaphores.
index fd49d69e35e0d45a769057f5eecc41c81f5330ab..22b6b7fade82f19ad5849984528f0203010bdffb 100644 (file)
@@ -1,6 +1,7 @@
 Files:
 tests/test-canonicalize-lgpl.c
 tests/signature.h
+tests/null-ptr.h
 tests/macros.h
 
 Depends-on:
index 6019349bec9e72b4bdf5dd7b541061a5657b61c6..e043a8dacaccb882e0d4994193d536ed56b71ced 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-canonicalize.c
+tests/null-ptr.h
 tests/macros.h
 
 Depends-on:
index 4738d5c8ddc7ba326ca9d2356c6c6df757829af0..28c00917a4f97534aa956eff91e3ca722d8ca566 100644 (file)
@@ -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
 
index 50b3f81065620671ed6cf1b4c86d928c4f97cc65..8f7928ebe312f04bb92d0140450f55919be53aea 100644 (file)
@@ -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 (file)
index 0000000..6743645
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.  */
+
+#include <stdlib.h>
+
+/* 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 .  */
index af20a0a215152ce99e59efc765d9e7be5108e253..c449f9893771cc504d4925c650114914a23d7d44 100644 (file)
@@ -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)
 {
index 0ba89fefd74f8ffaa8a19f4de7d0ab55359a2887..37a112630972d2401a9cb0a2582c3bfb66809d44 100644 (file)
 
 #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)
 {
index bbca811dca2757f4e220684c66572b5fcf8507e2..b2c23e6da5bb13d1f8a321bcfb583659dc2f61fb 100644 (file)
@@ -26,15 +26,10 @@ SIGNATURE_CHECK (memmem, void *, (void const *, size_t, void const *, size_t));
 #include <stdlib.h>
 #include <unistd.h>
 
+#include "null-ptr.h"
 #include "zerosize-ptr.h"
 #include "macros.h"
 
-static void *
-null_ptr (void)
-{
-  return NULL;
-}
-
 int
 main (int argc, char *argv[])
 {
index ed75ce7570f3c90f8bfc3a978101df6ba73a7364..2faf4c74d134871de513ba3b28770b76d4220a1d 100644 (file)
@@ -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)
 {