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

Joining HNG I started programming for a while now, my first language being python.

Have you seen this error? Files too large for Git?

Boilerplate code in Elm (Rant)

Which Are Free API for Ambica Sales Corporation Gold and Silver Live Rates?

Working with ASP.NET Core and DotVVM on Visual Studio Code

Enabling Self Service for your DataCenter — Part II

Getting started with QTUM staking for advanced users

Star Wars on Linux Terminal

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

Calculate Annual Income Tax Using Recursive Call

What is Compiler, Interpreter, Debugger, and Linker

C-Christmas tree

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