V3057. Function receives an odd argument.

The analyzer detected a possible error that has to do with passing a suspicious value as an argument to a function.

Consider the following examples:

Invalid characters in a path

string GetLogPath(string root)
{
  return System.IO.Path.Combine(root, @"\my|folder\log.txt");
}

A path containing invalid character '|' is passed to function Combine(). It will result in an ArgumentException.

The fixed version:

string GetLogPath(string root)
{
  return System.IO.Path.Combine(root, @"\my\folder\log.txt"); 
}

Invalid index

var pos = mask.IndexOf('\0');
if (pos != 0)
    asciiname = mask.Substring(0, pos);

IndexOf() returns the position of a specified argument. If the argument is not found, the function returns the value '-1'. And passing a negative index to function Substring() results in an ArgumentOutOfRangeException.

The fixed version:

var pos = mask.IndexOf('\0');
if (pos > 0)
    asciiname = mask.Substring(0, pos);

Suspicious argument to format function

string.Format(mask, 1, 2, mask);

The string.Format() function replaces one or more format items in a specified string. An attempt to write the same string into the format string is treated as suspicious by the analyzer.



Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++ and C#

goto PVS-Studio;