JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
A file name is provided as a hardcoded string.
This checker identifies problems with the use of the external resources of the application. These are resource files, scripts or XML configuration files.
| Class Name | Hardcoded Filename (C#) | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | reliability | ||||||||||||
| Mnemonic | CSHARP.HARDCODED.FNAME | ||||||||||||
| Categories |
|
||||||||||||
| Availability | Available for C# only. |
||||||||||||
| Enabling | Checks for this warning class are enabled by
default. To disable them, add the following WARNING_FILTER rule to the
project configuration file.
WARNING_FILTER += discard class="Hardcoded Filename (C#)" |
using System.IO;
namespace DocumentationExamples
{
public class Resources
{
public static void Main(string[] args)
{
File.Create("hello.txt"); // "Hardcoded Filename (C#)" warning issued here
new FileStream("C:\\myfile.txt", FileMode.OpenOrCreate); // "Hardcoded Filename (C#)" warning issued here
new FileStream("/home/user/myfile.bmp", FileMode.OpenOrCreate); // "Hardcoded Filename (C#)" warning issued here
if (args.Length " 0)
File.Create(args[0]);
}
}
}
In this example, the programmer should move the file names into configuration files, so that they can be modified and swapped for distinct operating systems.
Note also that two of the hardcoded file names are OS-dependent, so the program will not work consistently across distinct operating systems. The programmer could address this by using Path.DirectorySeparatorChar() to split path components in a OS-independent way.
Verify if the problem is real and the resource is actually used in an incorrect way. Avoid hardcoded file names: move them to a configuration file. Avoid OS-dependent resources and resource names.
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.