Re: R_OpenSiteFile: Do not use a null ptr as filename in fopen (PR#312)

About this list Date view Thread view Subject view Author view Other groups

Subject: Re: R_OpenSiteFile: Do not use a null ptr as filename in fopen (PR#312)
guido@hal.stat.unipd.it
Date: Thu 04 Nov 1999 - 19:50:55 EST


Message-Id: <199911040950.KAA28506@pubhealth.ku.dk>

On Thu, Nov 04, 1999 at 10:09:05AM +0100, hoffmann@ehmgs2.et.tu-dresden.de wrote:
>
> The reason is, that in unix/sys-common.c in R_OpenSiteFile() fopen
> is called with a null ptr as filename (because this is the outcome
> of getenv()).
>
> Although most compilers seem to interpret this as "file not found",
> this is an undefined behavior concerning to all C standards I could get
> hold of.
>
> A request in comp.lang.c gave the following response:
> ...
> Your program should crash. If you might get a NULL pointer as
> a filename, you should have a conditional statement to handle
> that case.
> ...
>

The same happens also under Windows where, for this reason,
'R_fopen' is defined as
 
FILE *R_fopen(const char *filename, const char *mode)
{
    if (!filename)
        return NULL;
    return (fopen(filename, mode));
}

g.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Tue 04 Jan 2000 - 14:16:09 EST