A few more words about the PVS-Studio V751 diagnostic (parameter is not used inside function’s body)

After we posted a small note, “Everybody makes mistakes when writing comparison functions”, we got an active discussion at the Hacker News website. Unfortunately, in the original note, I did not talk about how the diagnostic, that detected the error in OpenSSL, worked.

So I want to add an explanation. As I see from the comments, many of you thought that the PVS-Studio analyzer warns about a function’s unused argument. That’s not quite so. Or, to be precise, this is so, but the analyzer processes this case smarter than most linters or compilers.

It’s a bad idea to program an analyzer so that it just issues a warning to unused arguments. Such analyzer would produce many false positives, which is why many developers don’t look at (or disable) these warnings in their compilers/analyzers.

The PVS-Studio analyzer implements sort of empirical “magic”. PVS-Studio relies on the fact that there are arguments of the same type and some of them are not used, while the other ones are used several times. At the same time, there are a number of exceptions to the rule. For example, the diagnostic is not triggered if the number of unused arguments exceeds two.

All this allows the V751 diagnostic to issue few false positives, which makes the tool surpass its competitors. To be exact, when developing PVS-Studio, we do not implement rules if we cannot make them better than those of the compilers. Thanks to the diagnostic I described above, one can find interesting errors — like this one.

P.S. The PVS-Studio analyzer also provides a “stupid” version of this diagnostic — V2537. It was developed to check code against MISRA C and MISRA C++ standards. But the case above was special and by default this diagnostic was disabled — same as the other ones related to MISRA.

--

--

--

Co-founder of the PVS-Studio project. Microsoft MVP in the ‘Developer Technologies’ nomination and PhD in Physics and Mathematics.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Auto Git Config for VS Code Remote Container Development

Use This API To Find Out The Rhenium Spot Pricing

The Best Screenshot Tools For Windows 10

CS373 Spring 2022: Shreya Sridhar

How to reverse a string in Python?

Apache Airflow: You need to know this before getting started

My Genesys stories. #Learnable20

Join Major Commodity Trading Industries By Using An API

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrey Karpov

Andrey Karpov

Co-founder of the PVS-Studio project. Microsoft MVP in the ‘Developer Technologies’ nomination and PhD in Physics and Mathematics.

More from Medium

How to Create a Basic Arithmetic Programming Language — Part 2 | Sea #1b

Hardware Design Vs PCB Design

From human to binary: A basic guide through the compilation process in C.

266 Palindrome Permutation