Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!news.funet.fi!funic!fuug!demos!avg From: avg@hq.demos.su (Vadim G. Antonov) Newsgroups: comp.unix.questions Subject: Re: Strcpy on SysV vs. BSD. Message-ID: <1990Sep1.194237.2459@hq.demos.su> Date: 1 Sep 90 19:42:37 GMT References: <24351@adm.BRL.MIL> Reply-To: avg@hq.demos.su (Vadim G. Antonov) Organization: DEMOS, Moscow, USSR Lines: 33 In article <24351@adm.BRL.MIL> hsw@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)