Announcement: Be excellent to each other.


Caravel Forum : DROD Boards : Bugs : variable-size array declaration
New Topic New Poll Post Reply
Poster Message
schep
Level: Smitemaster
Avatar
Rank Points: 865
Registered: 03-01-2005
IP: Logged
icon variable-size array declaration (+2)  
Happened to spot this line while debugging: BackEndLib/Files.cpp, FindDataPathDotTxt(), Line 1193:
	char datEnvVar[wDatEnvVar.length() + 1];

g++ can handle that, and apparently some version of MS's compiler, but it's not globally valid C++. In fact, an acquaintance says VC++ 2005 doesn't compile similar code. A quick test with the -pedantic flag gets g++ telling me 'error: ISO C++ forbids variable-size array'. Since UnicodeToAscii already has a string overload, I recommend replacing that line and the next two with:
  string datEnvVar;
  UnicodeToAscii(wDatEnvVar, datEnvVar);
  for (string::iterator env_char=datEnvVar.begin();
       env_char!=datEnvVar.end(); ++env_char)
    *env_char = toupper(*env_char);


[Last edited by schep at 09-16-2007 09:57 PM : unedit: meant to quote-reply]
09-11-2007 at 01:59 AM
View Profile Send Private Message to User Send Email to User Show all user's posts This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5471
Registered: 02-04-2003
IP: Logged
icon Re: variable-size array declaration (0)  
schep wrote:
Happened to spot this line while debugging: BackEndLib/Files.cpp, FindDataPathDotTxt(), Line 1193:
	char datEnvVar[wDatEnvVar.length() + 1];


g++ can handle that, and apparently some version of MS's compiler, but it's not globally valid C++. In fact, an acquaintance says VC++ 2005 doesn't compile similar code. A quick test with the -pedantic flag gets g++ telling me 'error: ISO C++ forbids variable-size array'. Since UnicodeToAscii already has a string overload, I recommend replacing that line and the next two with:
  string datEnvVar;
  UnicodeToAscii(wDatEnvVar, datEnvVar);
  for (string::iterator env_char=datEnvVar.begin();
       env_char!=datEnvVar.end(); ++env_char)
    *env_char = toupper(*env_char);
Good suggestion. Will do -- thanks!
09-11-2007 at 04:15 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
schep
Level: Smitemaster
Avatar
Rank Points: 865
Registered: 03-01-2005
IP: Logged
icon Re: variable-size array declaration (+1)  
Whoops. That was just off the top of my head, but it needs one more change on the next line. And since this function is #ifdef-ed out for the Windows build, it went unnoticed until I got the changed code and actually tried to compile it. Just add a c_str() call to the next non-comment line:
  string datEnvVar;
  UnicodeToAscii(wDatEnvVar, datEnvVar);
  for (string::iterator env_char=datEnvVar.begin();
       env_char!=datEnvVar.end(); ++env_char)
    *env_char = toupper(*env_char);

  // Then try path in environment variable, app path and the dat search path.
  if ((UnwrinkleEnvPath(datEnvVar.c_str(), wstrTmp)

09-16-2007 at 09:57 PM
View Profile Send Private Message to User Send Email to User Show all user's posts This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5471
Registered: 02-04-2003
IP: Logged
icon Re: variable-size array declaration (0)  
schep wrote:
Whoops. That was just off the top of my head, but it needs one more change on the next line. And since this function is #ifdef-ed out for the Windows build, it went unnoticed until I got the changed code and actually tried to compile it. Just add a c_str() call to the next non-comment line:
  string datEnvVar;
  UnicodeToAscii(wDatEnvVar, datEnvVar);
  for (string::iterator env_char=datEnvVar.begin();
       env_char!=datEnvVar.end(); ++env_char)
    *env_char = toupper(*env_char);

  // Then try path in environment variable, app path and the dat search path.
  if ((UnwrinkleEnvPath(datEnvVar.c_str(), wstrTmp)
Thank you. Fixed.
09-19-2007 at 01:27 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
New Topic New Poll Post Reply
Caravel Forum : DROD Boards : Bugs : variable-size array declaration
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.9
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.