hoffmann@ehmgs2.et.tu-dresden.de
1999-Nov-04 09:09 UTC
R_OpenSiteFile: Do not use a null ptr as filename in fopen (PR#312)
I get crashes when I call R without any arguments and having no environment variables R_PROFILE and RPROFILE. 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. ... So I would suggest to test for the return value of getenv, before using it as filename in fopen. --please do not edit the information below-- Version: platform = hppa1.1-hp-hpux10.20 arch = hppa1.1 os = hpux10.20 system = hppa1.1, hpux10.20 status = status.rev = 0 major = 0 minor = 65.0 year = 1999 month = August day = 27 language = R Search Path: .GlobalEnv, Autoloads, package:base -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
guido@hal.stat.unipd.it
1999-Nov-04 09:50 UTC
R_OpenSiteFile: Do not use a null ptr as filename in fopen (PR#312)
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._