Path: utzoo!utgpu!watserv1!watmath!att!rutgers!cs.utexas.edu!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.unix.questions Subject: Re: Strcpy on SysV vs. BSD. Message-ID: <1990Sep02.141536.11663@virtech.uucp> Date: 2 Sep 90 14:15:36 GMT References: <24351@adm.BRL.MIL> Reply-To: cpcahil@virtech.UUCP (Conor P. Cahill) Organization: Virtual Technologies Inc., Sterling VA Lines: 33 In article <24351@adm.BRL.MIL> hsw@sparta.com (Howard Weiss) writes: >main(){ > char *TTx = "/dev/"; > char tty[10]; /* works on both SysV and BSD */ >/* char *tty; /* works only on BSD */ While you might get away with the *tty stuff for small strings on BSD systems, it in very bad code. What is hapening is that *tty is getting a default value (probably Zero in this case) and you are then writing data to that location (which has not been allocated to you and which *should* result in a core dump). The fact that you didn't get a core dump probably means that the startup code on your BSD system happens to leave some non-zero data on the stack that just happens to point to an area that you can write to. This is not expected behavior and will probably not work in all cases (even under your BSD system). Remember, you can NEVER NEVER NEVER write to an area pointed to by a pointer that you have not yet initialized (set to point to a data area that you can write to) and expect the code to work. >I've worked on UNIX systems since V6 (in 1976) and I've never seen >this before. I don't know what systems you have tried this on before, but It should fail on almost every system (or at least it should clobber some other variables). -- Conor P. Cahill (703)430-9247 Virtual Technologies, Inc., uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160 Sterling, VA 22170