News for hackers. Stuff that matters.
Re:C Programming Guidelines by nitrogen on Wednesday September 02, 2015 @01:12AM (#10157542)
I think the C standard library would be easier to work with if they would've taken this further, and required, for example, fclose(NULL) to be a no-op.

There's always the counterargument that cleanup code that hides a missing allocation can mask bugs elsewhere, if for example a FILE * debug was never fopen()ed, only gets written to in exceptional cases, and fclose(NULL) ignores.

Re:C Programming Guidelines by mieko on Wednesday September 02, 2015 @01:24AM (#10157574)
I'd personally err on the side of clearer clean-up code, but this a good point (and a view shared with glibc and BSD-derived libcs that intentionally segfault in this case).
Re:C Programming Guidelines by userbinator on Wednesday September 02, 2015 @01:44AM (#10157617)
I wouldn't describe that as an "intentional" segfault, but rather a "natural" one, the default behaviour you get on a system with an MMU. The null case with free() is a special-case extra check explicitly inserted in the code.
Re:C Programming Guidelines by mieko on Wednesday September 02, 2015 @02:30AM (#10157725)
"Intentional" was perhaps the wrong word for glibc, but BSD libc (at least on FreeBSD and OS X) actually document it as intentional:

    NOTES
    
    The fclose() function does not handle NULL arguments; they will result in 
    a segmentation violation.  This is intentional - it makes it easier to make 
    sure programs written under FreeBSD are bug free.  This behaviour is an 
    implementation detail, and programs should not rely upon it.
I thought I remembered similar wording for glibc, but I appear to have been mistaken.