To get a trial key
fill out the form below
Team License (standard version)
Enterprise License (extended version)
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
>
V3086. Variables are initialized throug…
Analyzer Diagnostics
General Analysis (C++)
General Analysis (C#)
General Analysis (Java)
Diagnosis of micro-optimizations (C++)
Diagnosis of 64-bit errors (Viva64, C++)
MISRA errors
AUTOSAR errors
Additional information
Contents

V3086. Variables are initialized through the call to the same function. It's probably an error or un-optimized code.

April 14, 2016

The analyzer detected a possible error that deals with two different variables being initialized by the same expression. Not all of such expressions are treated as unsafe but only those where function calls are used (or too long expressions).

Here is the simplest case:

x = X();
y = X();

Three scenarios are possible:

  • The code contains an error, which should be fixed by replacing 'X()' with 'Y()'.
  • The code is correct but works slowly. If the 'X()' function is required to perform multiple calculations, a better way is to write 'y = x;'.
  • The code is correct and works with proper speed, or the 'X()' function reads the value from a file. To suppress the false positive in this case, use the comment "//-V3086".

Now consider the following example from real code:

string frameworkPath = 
  Path.Combine(tmpRootDirectory, frameworkPathPattern);
string manifestFile = 
  Path.Combine(frameworkPath, "sdkManifest.xml");

string frameworkPath2 = 
  Path.Combine(tmpRootDirectory, frameworkPathPattern2);
string manifestFile2 = 
  Path.Combine(frameworkPath, "sdkManifest.xml");

There is a copy-paste error in this code, which is not easy to notice at first. Actually, it deals with mistakenly passing the first part of the path to the 'Path.Combine' function when receiving the 'manifestFile2' string. The code logic suggests that variable 'frameworkPath2' should be used instead of the originally used 'frameworkPath' variable.

The fixed code should look like this:

string manifestFile2 = 
  Path.Combine(frameworkPath2, "sdkManifest.xml");

This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →
Accept