Skip to contentSkip to conversation

Add note about calling fclose(NULL)

PATCH In review Thomas Jarosch 3 participants 7 messages Jan 29, 2013 – Feb 2, 2013 2 messages not in the archive Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add note about calling fclose(NULL)

---
 man3/fclose.3 | 4 ++++
 1 file changed, 4 insertions(+)
man3/fclose.3 +4 -0
index 1bdf0a5..6945e89 100644
@@ -97,6 +97,10 @@ on disk the kernel buffers must be flushed too, for example, with
 .BR sync (2)
 or
 .BR fsync (2).
+Also it's undefined behavior to call
+.BR fclose ()
+with a NULL pointer.
+
 .SH "SEE ALSO"
 .BR close (2),
 .BR fcloseall (3),
Signature · 6 lines
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

man3/fclose.3 on disk the kernel buffers must be flushed too, for · line 106

Quoted 13 lines · On Tuesday 29 January 2013 11:24:43 Thomas Jarosch wrote:
man3/fclose.3 +4 -0
@@ -97,6 +97,10 @@ on disk the kernel buffers must be flushed too, for
 example, with .BR sync (2)
 or
 .BR fsync (2).
+Also it's undefined behavior to call
+.BR fclose ()
+with a NULL pointer.
+
 .SH "SEE ALSO"
 .BR close (2),
 .BR fcloseall (3),

i wonder if it'd be better placed in the DESCRIPTION section -mike

A message that is not in the archive (sent off-list or not yet received): 201301291344.29011.vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org

#3 lore raw

Hi Mike,

Quoted 14 lines · On Tuesday, 29. January 2013 13:44:28 you wrote:
Quoted 13 lines · On Tuesday 29 January 2013 11:24:43 Thomas Jarosch wrote:
man3/fclose.3 +4 -0
@@ -97,6 +97,10 @@ on disk the kernel buffers must be flushed too, for
 example, with .BR sync (2)
 
 or
 .BR fsync (2).
 
+Also it's undefined behavior to call
+.BR fclose ()
+with a NULL pointer.
+
 
Quoted 5 lines
Quoted 3 lines

.SH "SEE ALSO"
.BR close (2),
.BR fcloseall (3),

i wonder if it'd be better placed in the DESCRIPTION section

I first added it there and then thought it's too prominent. The "NOTES" section seemed like a better place.

Let's see if it gets accepted at all.

Thomas

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 18 lines · On Friday 01 February 2013 04:43:21 Thomas Jarosch wrote:
Quoted 16 lines · On Tuesday, 29. January 2013 13:44:28 you wrote:

man3/fclose.3 on disk the kernel buffers must be flushed too, for · line 106

Quoted 13 lines · On Tuesday 29 January 2013 11:24:43 Thomas Jarosch wrote:
man3/fclose.3 +4 -0
@@ -97,6 +97,10 @@ on disk the kernel buffers must be flushed too, for
 example, with .BR sync (2)
 or
 .BR fsync (2).
+Also it's undefined behavior to call
+.BR fclose ()
+with a NULL pointer.
+
 .SH "SEE ALSO"
 .BR close (2),
 .BR fcloseall (3),

i wonder if it'd be better placed in the DESCRIPTION section

Quoted 2 lines

I first added it there and then thought it's too prominent. The "NOTES" section seemed like a better place.

looking at other pages, argument behavior is in the DESCRIPTION rather than NOTES, including discussion of undefined behavior. keeping it higher up is probably better too since NOTES tends to get lost by readers while DESCRIPTION is absorbed most frequently.
-mike

#5 lore raw
In reply to Thomas Jarosch

Thomas,

Could you supply some explanation of why you think this patch is required?

Thanks,

Michael

Quoted 24 lines · Thomas Jarosch
---
 man3/fclose.3 | 4 ++++
 1 file changed, 4 insertions(+)
man3/fclose.3 +4 -1
index 1bdf0a5..6945e89 100644
@@ -97,6 +97,10 @@ on disk the kernel buffers must be flushed too, for example, with
 .BR sync (2)
 or
 .BR fsync (2).
+Also it's undefined behavior to call
+.BR fclose ()
+with a NULL pointer.
+
 .SH "SEE ALSO"
 .BR close (2),
 .BR fcloseall (3),
--

1.7.11.7

Signature · 7 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface"; http://man7.org/tlpi/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): CAKgNAkiQsWWWTfLWeixN5+GcwkfP6UX+AYdL4HY6beq7rdpUxw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#7 lore raw
Quoted 10 lines · On Thursday, 31. January 2013 01:50:49 Michael Kerrisk wrote:
Quoted 10 lines
man3/fclose.3 +0 -0
index 1bdf0a5..6945e89 100644
@@ -97,6 +97,10 @@ on disk the kernel buffers must be flushed too, for

example, with>
.BR sync (2)
or
.BR fsync (2).

Quoted 6 lines

man3/fclose.3 on disk the kernel buffers must be flushed too, for example, with · line 103

Quoted 4 lines
man3/fclose.3 +4 -0
+Also it's undefined behavior to call
+.BR fclose ()
+with a NULL pointer.
+

Could you supply some explanation of why you think this patch is required?

I always thought fclose(NULL) behaves like free(NULL) and even sent a patch for the "perf" utility assuming this. Luckily Arnaldo caught the error before applying the patch, at least in one case.

Also fclose(NULL) "works" fine on HP-UX and Solaris, glibc will die with a segfault.

Cheers,
Thomas

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw
Quoted 18 lines · Thomas Jarosch
Quoted 10 lines · On Thursday, 31. January 2013 01:50:49 Michael Kerrisk wrote:
Quoted 10 lines
man3/fclose.3 +0 -0
index 1bdf0a5..6945e89 100644
@@ -97,6 +97,10 @@ on disk the kernel buffers must be flushed too, for

example, with>
.BR sync (2)
or
.BR fsync (2).

Quoted 6 lines

man3/fclose.3 on disk the kernel buffers must be flushed too, for example, with · line 103

Quoted 4 lines
man3/fclose.3 +4 -0
+Also it's undefined behavior to call
+.BR fclose ()
+with a NULL pointer.
+

Could you supply some explanation of why you think this patch is required?

Quoted 7 lines

I always thought fclose(NULL) behaves like free(NULL) and even sent a patch for the "perf" utility assuming this. Luckily Arnaldo caught the error before applying the patch, at least in one case.

Also fclose(NULL) "works" fine on HP-UX and Solaris, glibc will die with a segfault.

Thomas,

Can you define "works" with respect to those OSes? Their man pages seems to say nothing about fclose(NULL). At this stage, I'm not convinced that adding this text to the man page is really required.

Thanks,

Michael

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html