bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* include <stdlib.h> when needed
@ 2019-06-30 14:14 Bruno Haible
  2019-06-30 16:09 ` Jim Meyering
  0 siblings, 1 reply; 2+ messages in thread
From: Bruno Haible @ 2019-06-30 14:14 UTC (permalink / raw)
  To: bug-gnulib

[-- Attachment #1: Type: text/plain, Size: 1054 bytes --]

I got warnings about a missing #include <stdlib.h> in windows-tls.c.
Some other files also need <stdlib.h>, and it should better be done explicitly
rather than implicitly or by accident.


2019-06-30  Bruno Haible  <bruno@clisp.org>

	Include <stdlib.h> when needed.
	* lib/areadlinkat.c: Include <stdlib.h>, needed for free() in at-func.c.
	* lib/faccessat.c: Likewise.
	* lib/fchmodat.c: Likewise.
	* lib/fchownat.c: Likewise.
	* lib/fstatat.c: Likewise.
	* lib/mkfifoat.c: Likewise.
	* lib/mknodat.c: Likewise.
	* lib/readlinkat.c: Likewise.
	* lib/symlinkat.c: Likewise.
	* lib/utimensat.c: Likewise.
	* lib/mkdirat.c: Likewise. Include also the specification header.

2019-06-30  Bruno Haible  <bruno@clisp.org>

	Include <stdlib.h> when needed.
	* lib/cnd.c: Include <stdlib.h>, needed for abort().
	* lib/fcntl.c: Likewise.
	* lib/mbscasestr.c: Likewise.
	* lib/mbssep.c: Likewise.
	* lib/mbsstr.c: Likewise.
	* lib/openat.c: Include <stdlib.h>, needed for free().
	* lib/windows-tls.c: Include <stdlib.h>, needed for malloc(), free(),
	abort().


[-- Attachment #2: 0001-Include-stdlib.h-when-needed.patch --]
[-- Type: text/x-patch, Size: 5219 bytes --]

From 3712d6cd285b2bd42592b2d7bd5bf4645f6d443c Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Sun, 30 Jun 2019 15:52:09 +0200
Subject: [PATCH 1/2] Include <stdlib.h> when needed.

* lib/areadlinkat.c: Include <stdlib.h>, needed for free() in at-func.c.
* lib/faccessat.c: Likewise.
* lib/fchmodat.c: Likewise.
* lib/fchownat.c: Likewise.
* lib/fstatat.c: Likewise.
* lib/mkfifoat.c: Likewise.
* lib/mknodat.c: Likewise.
* lib/readlinkat.c: Likewise.
* lib/symlinkat.c: Likewise.
* lib/utimensat.c: Likewise.
* lib/mkdirat.c: Likewise. Include also the specification header.
---
 ChangeLog         | 15 +++++++++++++++
 lib/areadlinkat.c |  2 ++
 lib/faccessat.c   |  3 +++
 lib/fchmodat.c    |  2 ++
 lib/fchownat.c    |  2 ++
 lib/fstatat.c     |  1 +
 lib/mkdirat.c     |  4 ++++
 lib/mkfifoat.c    |  3 +++
 lib/mknodat.c     |  3 +++
 lib/readlinkat.c  |  5 ++++-
 lib/symlinkat.c   |  3 +++
 lib/utimensat.c   |  2 ++
 12 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 2fc31a3..f554b5d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2019-06-30  Bruno Haible  <bruno@clisp.org>
 
+	Include <stdlib.h> when needed.
+	* lib/areadlinkat.c: Include <stdlib.h>, needed for free() in at-func.c.
+	* lib/faccessat.c: Likewise.
+	* lib/fchmodat.c: Likewise.
+	* lib/fchownat.c: Likewise.
+	* lib/fstatat.c: Likewise.
+	* lib/mkfifoat.c: Likewise.
+	* lib/mknodat.c: Likewise.
+	* lib/readlinkat.c: Likewise.
+	* lib/symlinkat.c: Likewise.
+	* lib/utimensat.c: Likewise.
+	* lib/mkdirat.c: Likewise. Include also the specification header.
+
+2019-06-30  Bruno Haible  <bruno@clisp.org>
+
 	inet_ntop, inet_pton: Avoid conflict with native Windows functions.
 	* m4/sys_socket_h.m4 (gl_PREREQ_SYS_H_WS2TCPIP): New macro, extracted
 	from gl_PREREQ_SYS_H_SOCKET.
diff --git a/lib/areadlinkat.c b/lib/areadlinkat.c
index 6dfbb61..fd9e2f2 100644
--- a/lib/areadlinkat.c
+++ b/lib/areadlinkat.c
@@ -25,6 +25,8 @@
 /* Specification.  */
 #include "areadlink.h"
 
+#include <stdlib.h>
+
 #include "careadlinkat.h"
 
 #if HAVE_READLINKAT
diff --git a/lib/faccessat.c b/lib/faccessat.c
index 6c63e61..e8e581a 100644
--- a/lib/faccessat.c
+++ b/lib/faccessat.c
@@ -22,9 +22,12 @@
 #define _GL_INCLUDING_UNISTD_H
 #include <config.h>
 
+/* Specification.  */
 #include <unistd.h>
+
 #include <errno.h>
 #include <fcntl.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 #undef _GL_INCLUDING_UNISTD_H
diff --git a/lib/fchmodat.c b/lib/fchmodat.c
index 088d3c0..ea55f65 100644
--- a/lib/fchmodat.c
+++ b/lib/fchmodat.c
@@ -18,9 +18,11 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include <sys/stat.h>
 
 #include <errno.h>
+#include <stdlib.h>
 
 #ifndef HAVE_LCHMOD
 /* Use a different name, to avoid conflicting with any
diff --git a/lib/fchownat.c b/lib/fchownat.c
index 538d86d..9fb9ce9 100644
--- a/lib/fchownat.c
+++ b/lib/fchownat.c
@@ -23,9 +23,11 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include <unistd.h>
 
 #include <errno.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include "openat.h"
diff --git a/lib/fstatat.c b/lib/fstatat.c
index 019d3c6..db864da 100644
--- a/lib/fstatat.c
+++ b/lib/fstatat.c
@@ -49,6 +49,7 @@ orig_fstatat (int fd, char const *filename, struct stat *buf, int flags)
 
 #include <errno.h>
 #include <fcntl.h>
+#include <stdlib.h>
 #include <string.h>
 
 #if HAVE_FSTATAT && HAVE_WORKING_FSTATAT_ZERO_FLAG
diff --git a/lib/mkdirat.c b/lib/mkdirat.c
index 21c09cc..fd53d83 100644
--- a/lib/mkdirat.c
+++ b/lib/mkdirat.c
@@ -18,6 +18,10 @@
 
 #include <config.h>
 
+/* Specification.  */
+#include <sys/stat.h>
+
+#include <stdlib.h>
 #include <unistd.h>
 
 /* Solaris 10 has no function like this.
diff --git a/lib/mkfifoat.c b/lib/mkfifoat.c
index 8e44ade..2ed7aeb 100644
--- a/lib/mkfifoat.c
+++ b/lib/mkfifoat.c
@@ -18,8 +18,11 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include <sys/stat.h>
 
+#include <stdlib.h>
+
 #if !HAVE_MKFIFO
 
 # include <errno.h>
diff --git a/lib/mknodat.c b/lib/mknodat.c
index 0cec0d3..c5ca756 100644
--- a/lib/mknodat.c
+++ b/lib/mknodat.c
@@ -18,8 +18,11 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include <sys/stat.h>
 
+#include <stdlib.h>
+
 #if !HAVE_MKNOD
 
 # include <errno.h>
diff --git a/lib/readlinkat.c b/lib/readlinkat.c
index c0f3e59..0694116 100644
--- a/lib/readlinkat.c
+++ b/lib/readlinkat.c
@@ -18,8 +18,11 @@
 
 #include <config.h>
 
-#include <errno.h>
+/* Specification.  */
 #include <unistd.h>
+
+#include <errno.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 
diff --git a/lib/symlinkat.c b/lib/symlinkat.c
index 7d58cd9..4f7df8e 100644
--- a/lib/symlinkat.c
+++ b/lib/symlinkat.c
@@ -18,8 +18,11 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include <unistd.h>
+
 #include <errno.h>
+#include <stdlib.h>
 
 #if HAVE_SYMLINKAT
 # undef symlinkat
diff --git a/lib/utimensat.c b/lib/utimensat.c
index e9ea626..ebd339d 100644
--- a/lib/utimensat.c
+++ b/lib/utimensat.c
@@ -18,10 +18,12 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include <sys/stat.h>
 
 #include <errno.h>
 #include <fcntl.h>
+#include <stdlib.h>
 
 #include "stat-time.h"
 #include "timespec.h"
-- 
2.7.4


[-- Attachment #3: 0002-Include-stdlib.h-when-needed.patch --]
[-- Type: text/x-patch, Size: 3430 bytes --]

From fcd36afd142c6b0969016314982c02dc66985b1f Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Sun, 30 Jun 2019 16:11:08 +0200
Subject: [PATCH 2/2] Include <stdlib.h> when needed.

* lib/cnd.c: Include <stdlib.h>, needed for abort().
* lib/fcntl.c: Likewise.
* lib/mbscasestr.c: Likewise.
* lib/mbssep.c: Likewise.
* lib/mbsstr.c: Likewise.
* lib/openat.c: Include <stdlib.h>, needed for free().
* lib/windows-tls.c: Include <stdlib.h>, needed for malloc(), free(),
abort().
---
 ChangeLog         | 12 ++++++++++++
 lib/cnd.c         |  1 +
 lib/fcntl.c       |  1 +
 lib/mbscasestr.c  |  1 +
 lib/mbssep.c      |  2 ++
 lib/mbsstr.c      |  1 +
 lib/openat.c      |  1 +
 lib/windows-tls.c |  1 +
 8 files changed, 20 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index f554b5d..a183dd4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,18 @@
 2019-06-30  Bruno Haible  <bruno@clisp.org>
 
 	Include <stdlib.h> when needed.
+	* lib/cnd.c: Include <stdlib.h>, needed for abort().
+	* lib/fcntl.c: Likewise.
+	* lib/mbscasestr.c: Likewise.
+	* lib/mbssep.c: Likewise.
+	* lib/mbsstr.c: Likewise.
+	* lib/openat.c: Include <stdlib.h>, needed for free().
+	* lib/windows-tls.c: Include <stdlib.h>, needed for malloc(), free(),
+	abort().
+
+2019-06-30  Bruno Haible  <bruno@clisp.org>
+
+	Include <stdlib.h> when needed.
 	* lib/areadlinkat.c: Include <stdlib.h>, needed for free() in at-func.c.
 	* lib/faccessat.c: Likewise.
 	* lib/fchmodat.c: Likewise.
diff --git a/lib/cnd.c b/lib/cnd.c
index 48c4854..0dfee4c 100644
--- a/lib/cnd.c
+++ b/lib/cnd.c
@@ -22,6 +22,7 @@
 #include <threads.h>
 
 #include <errno.h>
+#include <stdlib.h>
 
 #if defined _WIN32 && ! defined __CYGWIN__
 /* Use Windows threads.  */
diff --git a/lib/fcntl.c b/lib/fcntl.c
index 51f62ef..a3ffaa6 100644
--- a/lib/fcntl.c
+++ b/lib/fcntl.c
@@ -25,6 +25,7 @@
 #include <errno.h>
 #include <limits.h>
 #include <stdarg.h>
+#include <stdlib.h>
 #include <unistd.h>
 
 #ifdef __KLIBC__
diff --git a/lib/mbscasestr.c b/lib/mbscasestr.c
index 59be444..7c74ed7 100644
--- a/lib/mbscasestr.c
+++ b/lib/mbscasestr.c
@@ -23,6 +23,7 @@
 #include <ctype.h>
 #include <stdbool.h>
 #include <stddef.h>  /* for NULL, in case a nonstandard string.h lacks it */
+#include <stdlib.h>
 
 #include "malloca.h"
 #include "mbuiter.h"
diff --git a/lib/mbssep.c b/lib/mbssep.c
index ca3f20e..f301d66 100644
--- a/lib/mbssep.c
+++ b/lib/mbssep.c
@@ -20,6 +20,8 @@
 /* Specification.  */
 #include <string.h>
 
+#include <stdlib.h>
+
 #include "mbuiter.h"
 
 char *
diff --git a/lib/mbsstr.c b/lib/mbsstr.c
index 46bfdc6..4aaebfe 100644
--- a/lib/mbsstr.c
+++ b/lib/mbsstr.c
@@ -22,6 +22,7 @@
 
 #include <stdbool.h>
 #include <stddef.h>  /* for NULL, in case a nonstandard string.h lacks it */
+#include <stdlib.h>
 
 #include "malloca.h"
 #include "mbuiter.h"
diff --git a/lib/openat.c b/lib/openat.c
index 4ab4a31..3431147 100644
--- a/lib/openat.c
+++ b/lib/openat.c
@@ -46,6 +46,7 @@ orig_openat (int fd, char const *filename, int flags, mode_t mode)
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stddef.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <errno.h>
diff --git a/lib/windows-tls.c b/lib/windows-tls.c
index 02dfdfb..2e1b702 100644
--- a/lib/windows-tls.c
+++ b/lib/windows-tls.c
@@ -23,6 +23,7 @@
 
 #include <errno.h>
 #include <limits.h>
+#include <stdlib.h>
 
 #include "windows-once.h"
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: include <stdlib.h> when needed
  2019-06-30 14:14 include <stdlib.h> when needed Bruno Haible
@ 2019-06-30 16:09 ` Jim Meyering
  0 siblings, 0 replies; 2+ messages in thread
From: Jim Meyering @ 2019-06-30 16:09 UTC (permalink / raw)
  To: Bruno Haible; +Cc: bug-gnulib@gnu.org List

Nice. Thank you.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-30 16:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-30 14:14 include <stdlib.h> when needed Bruno Haible
2019-06-30 16:09 ` Jim Meyering

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).