尝试运行在 VS2012 中编译的以下代码时,我似乎遇到了内存损坏。
它在 VS2010 及以前的版本中运行良好:
char *var1 = getenv("var1"); // Value for var1 is correct here
char var2S[MAXSTRING];
sprintf(var2S, "VAR2=%s/a/%s/b", var1, getValue()); //Var2 looks correct
static const char *env_string = strdup(const_cast<char *>(var2S));
putenv((char *)env_string); // Value for var1 is corrupt after this call