modification of strings
Norman Joseph
norm at oglvee.UUCP
Mon Feb 6 23:59:57 AEST 1989
>From article <7429 at csli.STANFORD.EDU>, by gandalf at csli.STANFORD.EDU (Juergen Wagner):
> In article <345 at lakesys.UUCP> chad at 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!"
More information about the Comp.lang.c
mailing list