Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!decwrl!decvax!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: modification of strings Message-ID: <11711@haddock.ima.isc.com> Date: 8 Feb 89 20:39:24 GMT References: <7429@csli.STANFORD.EDU> <466@oglvee.UUCP> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 14 In article <466@oglvee.UUCP> norm@oglvee.UUCP (Norman Joseph) writes: >[The previous example overflows,] but what if the code looked like this: > 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? You'd better also assume that string literals are not shared. Even so, you may be in for a surprise when you execute this code fragment the second time, and find that blah[0]=='g' immediately after the initialization to (apparently) "meow". This kludge is confusing and unportable. Don't use it. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint