From hoffmann@ehmgs2.et.tu-dresden.de  Thu Nov  4 09:09:05 1999
From: hoffmann@ehmgs2.et.tu-dresden.de (hoffmann@ehmgs2.et.tu-dresden.de)
Date: Thu, 4 Nov 1999 10:09:05 +0100 (MET)
Subject: R_OpenSiteFile: Do not use a null ptr as filename in fopen (PR#312)
Message-ID: <199911040909.KAA27898@pubhealth.ku.dk>

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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


R_OpenSiteFile: Do not use a null ptr as filename in fopen (PR#312)
hoffmann@ehmgs2.et.tu-dresden.de