Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!rochester!pt.cs.cmu.edu!cadre!pitt!amanue!oglvee!norm From: norm@oglvee.UUCP (Norman Joseph) Newsgroups: comp.lang.c Subject: Re: modification of strings Message-ID: <466@oglvee.UUCP> Date: 6 Feb 89 13:59:57 GMT References: <7429@csli.STANFORD.EDU> Organization: Oglevee Computer Systems, Connellsville, Pa Lines: 24 From article <7429@csli.STANFORD.EDU>, by gandalf@csli.STANFORD.EDU (Juergen Wagner): > In article <345@lakesys.UUCP> chad@lakesys.UUCP (D. Chadwick Gibbons) writes: >> >> char *blah = "meow"; >> char *tmp; >> >> tmp = strcpy(blah, "grr, snarl, hiss"); > > and the stuff becomes hard to debug. Allocate all the memory you need, and > don't try to overwrite static strings. I can see that the above strcpy() will overwrite something somewhere since strlen( "meow" ) < strlen( "grr, snarl, hiss" ). But what if the code looked like this (ignoring `tmp' for this example): char *blah = "meow\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; strcpy( blah, "grr, snarl, hiss" ); assuming that you could write to the space into which `blah' pointed? -- Norm Joseph - Oglevee Computer System, Inc. UUCP: ...!{pitt,cgh}!amanue!oglvee!norm "Mate, that parrot wouldn't *VROOM* if you put four million volts through it!"