ansi c (almost on topic) was: [getting old punched cards read]

From: Paul E Coad <pcoad_at_wco.com>
Date: Fri Apr 24 14:38:28 1998

On Fri, 24 Apr 1998, Captain Napalm wrote:

> It was thus said that the Great Pete Turnbull once stated:
> >
> > On Apr 24, 1:35, Captain Napalm wrote:
> > > Well, I snagged a copy of it, compiled it, found a bug, and fixed it.
> > > strcpy() (at least on my compiler) will crash if any of the parameters
> > > are NULL pointers,
> >
> > That's a compiler (or library, actually) bug. You should be able to copy a
> > null string.
>
> Well, I've tried it across four platforms and five compilers (Linux/GCC,
> Solaris/native and GCC, AIX/native and HPUX/native) and three of the five
> core dumped.
>
> I checked the standard and it doesn't say what it should do in case one of
> the parameters is NULL, so I assume this is an implementation detail and the
> safest thing to do is assume you can't strcpy() a NULL pointer (which I do
> anyway).
>
> -spc (Considers that a feature, not a bug)

The ANSI standard is not completely silent on the matter, but does not
define the behavior.

According to section 4.1.6 Use of Library Functions:

"Each of the following statements applies unless explicitly stated
otherwise in the detailed descriptions that follow. If an argument
to a function has an invalid value (such as a value outside of the
domain of the function, or a pointer outside the address space of
the program or a null pointer), the behavior is undefined."

So says ANSI X3.159-1989. So shall it be.

--pec (who likes reading the standard a little too much)
--------------------------------------------------------------------------
The Antique Computer Collection: http://www.wco.com/~pcoad/machines.html
Received on Fri Apr 24 1998 - 14:38:28 BST

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:30:41 BST