Issue with '(' and ')'characters in PATH system environmental variable while using PVS-Studio with Visual Studio 2008

Paul Eremeev
Articles: 32



At times the users of PVS-Studio static analyzer encounter the following issue while starting the analysis using Visual Studio 2008 IDE: the analysis does not start and only one message of the following kind is produced

\Utilities\Bin\x86";"C:\WINDOWS\system32";"C:\WINDOWS";
"C:\WINDOWS\System32\Wbem";"C:\Program. was unexpected at this time.

After thoroughly investigating this issue we've determined that such a behavior is caused by an error in one of Visual Studio's environment configuration bat files. And this file is:

..\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat

The PVS-Studio analyzer uses vsvars32.bat file to configure the environment before launching Visual C++ preprocessor. It turns out that this particular issue is caused by the following fragment of the file:

@if not "%WindowsSdkDir%" == "" (
 set "PATH=%WindowsSdkDir%bin;%PATH%"
 set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%"
 set "LIB=%WindowsSdkDir%lib;%LIB%"
)

The issue will manifest itself if the PATH environmental variable will have been containing the '(' and ')' characters, as if for example Microsoft DirectX SDK will have been included into it - "C:\Program Files\Microsoft DirectX SDK (August 2006)\Utilities\Bin\x86". Than the statement following the 'if' operator

@if not "%WindowsSdkDir%" == "" (
 set "PATH=%WindowsSdkDir%bin;%PATH%"

will be terminated by one of the closing parentheses in PATH, as in this case ..August 2006), which results in the issue at hand.

This leaves us with two solutions of the problem:

  • Remove any path that has '(' and ')' characters from your PATH system environment variable.
  • Rewrite the 'If' statement using goto operator like this:
@if "%WindowsSdkDir%" == "" goto SkipSDKVariableSet

@set "PATH=%WindowsSdkDir%bin;%PATH%"
@set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%"
@set "LIB=%WindowsSdkDir%lib;%LIB%"

:SkipSDKVariableSet

The second path here creates another problem with installation of updates as they could rewrite this code fragment in vsvars32.bat file.



Use PVS-Studio to search for bugs in C, C++, C# and Java

We offer you to check your project code with PVS-Studio. Just one bug found in the project will show you the benefits of the static code analysis methodology better than a dozen of the articles.

goto PVS-Studio;

Paul Eremeev
Articles: 32


Bugs Found

Checked Projects
344
Collected Errors
12 970