Strcpy on SysV vs. BSD.
Vadim G. Antonov
avg at hq.demos.su
Sun Sep 2 05:42:37 AEST 1990
In article <24351 at adm.BRL.MIL> hsw at sparta.com (Howard Weiss) writes:
> Here is a short C program that demonstrates the problem:
>
>main(){
> char *TTx = "/dev/";
> char tty[10]; /* works on both SysV and BSD */
>/* char *tty; /* works only on BSD */
> strcpy(tty,TTx);
> printf("what's in tty now is %s\n",tty);
>}
>
>Yet, the 'char *tty' compiles and runs fine on BSD!
Generally speaking, it SHOULD NOT work because the only
thing this program do (commented version) is writing
bytes "/dev/" into some undefined place pointed by
uninitialized pointer `tty'. You're lucky: Sys V catched
you and did not allow you to make a hard mistake.
Errors of such sort are very easy to put and very hard
to get (out of the program).
>I've worked on UNIX systems since V6 (in 1976) and I've never seen
>this before.
I've also worked on Unix V6; but I've ran across
uninitialized pointers many times! :-)
>Howard Weiss
Vadim Antonov,
DEMOS, Moscow, USSR
(it is NOT a joke)
More information about the Comp.unix.questions
mailing list