On 29/10/2007, Joshua Juran <[EMAIL PROTECTED]> wrote: > On Oct 28, 2007, at 8:28 AM, Klaas-Jan Stol wrote: > > > hi, when building parrot it reported a warning about some variable > > "string" > > in string.c > > When checking out, I saw this: > > > > static const char * > > nonnull_encoding_name(STRING *s) > > { > > char *string; > > if (!s) > > strcpy(string, "null string"); > > else > > strcpy(string, s->encoding->name); > > > > return string; > > } > > > > Can this be right? > > No, it can't. > > > I thought that the first argument to strcpy needs to > > point to some memory, but "string" (which really should be renamed > > I think, > > Shouldn't be a problem if you're not 'using namespace std;'. I use > 'string' as a variable name in my C++ programs without ill effect. > > > as it might cause trouble when compiling it using a C++ compiler) > > is not > > even initialized. > > You're quite right -- the listed code is bonkers. If you're lucky, > you'll get a segfault attempting to write to unmapped memory.
This was pointed out by leo++ on #parrot who then described a far more elegant solution which was committed to the repo not long afterwards in r22563. Paul