Tony Mc said:
Ok, thanks for that reference, lots of interesting reading there. I
don't see that it shows that calling system() with a non-NULL pointer
invokes undefined behaviour, though the majority view seemed to be
that the standard had no way of defining the behaviour (and for some
that counted as UB in all but name, a point I can see but which I
think confuses the use of the term UB).
C99 3.4.3:
undefined behavior
behavior, upon use of a nonportable or erroneous program construct
or of erroneous data, for which this International Standard
imposes no requirements
NOTE Possible undefined behavior ranges from ignoring the
situation completely with unpredictable results, to behaving
during translation or program execution in a documented manner
characteristic of the environment (with or without the issuance of
a diagnostic message), to terminating a translation or execution
(with the issuance of a diagnostic message).
EXAMPLE An example of undefined behavior is the behavior on
integer overflow.
C99 4p2:
If a shall or shall not requirement that appears outside of a
constraint is violated, the behavior is undefined. Undefined
behavior is otherwise indicated in this International Standard by
the words undefined behavior or by the omission of any explicit
definition of behavior. There is no difference in emphasis among
these three; they all describe behavior that is undefined.
As I understand it, that makes
the call implementation defined (which the standard also cannot
define, but requires the implementation to), which is not the same as
undefined.
Here's what the standard says about system() (C99 7.20.4.6):
If *string* is a null pointer, the *system* function determines
whether the host environment has a _command processor_. If
*string* is not a null pointer, the *system* function passes the
string pointed to by *string* to that command processor to be
executed in a manner which the implementation shall document; this
might then cause the program calling *system* to behave in a
non-conforming manner or to terminate.
The standard uses boldface (which I've represented as *...*) and
italics (which I've represented as _..._).
This doesn't actually say that the behavior of system() with a
non-null argument is undefined, but behaving "in a non-conforming
manner" seems to me to be about as undefined as you can get.
Of course, an implementation is free to document the behavior.
[...]