# V631. Consider inspecting the 'Foo' function call. Defining an absolute path to the file or directory is considered a poor style.

The analyzer has detected a potential error that occurs when calling a function intended to handle files. An absolute path to a file or directory is passed into a function in one of the actual arguments. Using a function in such a way is dangerous, as there may be cases that this path doesn't exist on the user's computer.

Consider an example of incorrect code:

FILE *text = fopen("c:\\TEMP\\text.txt", "r");

A better way is to get the path to a file on certain conditions.

This is the correct code:

string fullFilePath = GetFilePath() + "text.txt";
FILE *text = fopen(fullFilePath.c_str(), "r");
 According to Common Weakness Enumeration, potential errors found by using this diagnostic are classified as CWE-37, CWE-39.
 You can look at examples of errors detected by the V631 diagnostic.

377
13 692