Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
How the CSS markup fragment broke the C…

How the CSS markup fragment broke the C++ compiler

Mar 27 2019

Static analysis methodology involves various technologies. One of them is preprocessing files right before analyzing them. Preprocessed files are created by the compiler that runs in a special working mode. Unfortunately, our long-standing experience of developing a static analyzer shows that this mode is not great for testing. In this note, I'll give the example of a fresh bug in the C++ compiler from Microsoft.

0620_MsvcBugCSS/image1.png

Introduction

To demonstrate capabilities of the PVS-Studio static analyzer our team checks code of open source projects. This is a significant contribution to the quality of open source software, extra publicity and testing of the analyzer. Sometimes we reveal some very unusual problems in compilers, which are difficult to deal with on the part of the analyzer. Thus, my colleague has recently written the article "The file with the 'import' directive is no longer working (compiler internal error 'msc1.cpp'). What shall we do?" to help our users in solving "someone else's" problem.

What's connection with CSS?

I've just found a no less interesting bug when checking a large project. The Microsoft compiler for C/C++ of the 19.16.27027.1 (Visual Studio v15.9.9) version has just issued such an error when analyzing several files:

fatal error C1021: invalid preprocessor command 'tooltiphint'

Obviously, it is not a preprocessor directive, but what is it? This is a fragment of CSS code:

#tooltiphint {
  position: fixed;
  width: 50em;
  margin-left: -25em;
  left: 50%;
  padding: 10px;
  border: 1px solid #b0b0b0;
  border-radius: 2px;
  box-shadow: 1px 1px 7px black;
  background-color: #c0c0c0;
  z-index: 2;
}

After taking a close look at the fragment, it became clear that the compiler gets wrong when preprocessing the file, whereas the code is compiled successfully. The fragment of the CSS code is a part of the C++ code string literal. Here is the example of code, enough to reproduce the error:

std::string test = R"<<<(
<style type="text/css">
body { color:#000000; background-color:#ffffff }
body { font-family:Helvetica, sans-serif; font-size:10pt }

#tooltiphint {
  position: fixed;
  width: 50em;
  margin-left: -25em;
  left: 50%;
  padding: 10px;
  border: 1px solid #b0b0b0;
  border-radius: 2px;
  box-shadow: 1px 1px 7px black;
  background-color: #c0c0c0;
  z-index: 2;
}
.macro {
  color: darkmagenta;
  background-color:LemonChiffon;
  /* Macros are position: relative to provide base for expansions. */
  position: relative;
}

</style>
</head>
<body>)<<<";

The above code fragment does not prevent successful compilation but, at the same time, an error will occur in the preprocessing mode (/P flag).

As you can see, the life of static analyzer developers is anything but simple :). It seems like PVS-Studio is not to blame, but we still have to deal with such problems. Well, no fresh news. You can check out some other similar cases in the article "PVS-Studio and Hostile Environment".

Conclusion

This issue will be sent to the official bug-tracker, but a quick solution of the problem is hardly possible. For example, the problem with the #import directive, mentioned at the beginning, which we detected several months ago, will be fixed only in the next Visual Studio release. Since the release of the new Visual Studio 2019 will be in a week, most likely they will not manage to fix this bug by that date. Users of PVS-Studio, we recommend that you also use the macro PVS_STUDIO.

UPD: A fix for this issue has been released in VS 2019 16.0 Preview 4 and VS 2019 16.0 RC.



Comments (0)

Next comments next comments
close comment form
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam