Strcat broken on win32 in 5.14/00

Hello,

I downloaded the “recommended” windows binary today, and find several of my macros from my UNIX boxen not working. I have discovered that it’s because strcat is not functioning under win32, though it works just fine on Solaris 10 and OS X 10.4.

Here’s a simple function example:

void teststrings(const char* label) {
   char* name = new char*;
   cout << "1) NAME: " << name << "\tLABEL: " << label << endl;
   strcpy(name,"base");
   cout << "2) NAME: " << name << "\tLABEL: " << label << endl;
   strcat(name,label);
   cout << "3) NAME: " << name << "\tLABEL: " << label << endl;
}

Under Solaris:
Version 4.00/02, 24 February 2004
Compiled for SolarisCC5
CINT/ROOT C/C++ Interpreter 5.15.123, Feb 9 2004
root [0] .L teststrings.C
root [1] teststrings(“hello”)

  1. NAME: LABEL: hello
  2. NAME: base LABEL: hello
  3. NAME: basehello LABEL: hello

Under OS X:
Version 5.14/00, 29 December, 2006
Compiled for macosx with thread support
CINT/ROOT C/C++ Interpreter 5.16.06, November 24, 2006
root [0] .L teststrings.C
root [1] teststrings(“hello”)

  1. NAME: LABEL: hello
  2. NAME: base LABEL: hello
  3. NAME: basehello LABEL: hello

Under win XP
Version 5.14/00, 14 December, 2006
Compiled for win32
CINT/ROOT C/C++ Interpreter 5.16.06, November 24, 2006
root [0] .L teststrings.C
root [1] teststrings(“hello”)

  1. NAME: LABEL: hello
  2. NAME: base LABEL: hello
  3. NAME: base LABEL: hello

I found one thread (root.cern.ch/phpBB2/viewtopic.php?t=1434) that seemed to indicate that Philippe found an error in the MS compiler, but this was supposedly fixed in 2005???

Any ideas as to what happened? Is there a “fixed” or non-optimized build for winXP that has a working strcat?

Many kind thanks,
-Don

Hi,
your “name=new…” does not allocate a buffer; it’s highly surprising that this worked on any platform. Instead do e.g. “char name[1024];”, where the 1024 must be sufficient to hold trhe whole string. Also you might use strlen to check for buffer overflows.
Cheers, Axel.

Hi Alex,

Thanks you’re right. That declaration should be:
"new char[strlen(label)+strlen(base)+1]"
where base is defined as my base name.

Thanks again,
-Don