TechBuzzPro

PC-lint False Positives: How to Suppress Them

· 5 min read · Windows & PC

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To suppress false positive warnings in PC-lint for a firmware codebase, use inline suppression comments such as //lint !e123 or //lint -e123 directly on the offending line, or configure a project-wide suppression file with the -e option and a lint configuration file. Inline comments are the quickest fix for isolated cases; a suppression file is better for recurring patterns across the codebase. Both methods keep the warning active everywhere else, so you do not lose real defects.

What You'll Need

  • PC-lint (or PC-lint Plus) installed and a working lint configuration for your firmware project.
  • Access to the source files and the lint configuration file (often named std.lnt, project.lnt, or similar).
  • Knowledge of the warning numbers you want to suppress (e.g., 534, 613, 818).
  • A text editor or IDE that can edit source files and configuration files.

Step-by-Step

  1. Identify the exact warning number and message. Run PC-lint on the file that produces the false positive. The output shows a number like Warning 534: Ignoring return value of function. Note the number and the line number. Do not suppress by message text; always use the numeric code.
  2. Decide on the suppression scope. For a single line, use an inline comment. For a whole function or block, use a push/pop pair. For a file or project-wide pattern, use a configuration file. Start with the narrowest scope that works.
  3. Add an inline suppression comment. Place //lint !e534 at the end of the line that triggers the warning. The ! means suppress only this instance; -e534 would suppress all instances in the file. For a block, use //lint -save before the block and //lint -restore after it, with //lint -e534 in between. Example:
    //lint -save -e534
    (void)write_register(addr, value); // no check needed here
    //lint -restore
    This keeps the suppression local and reversible.
  4. Use a suppression file for project-wide patterns. Create a file, e.g., suppress.lnt, containing lines like -e534 and -e613. Include it in your main lint configuration with //lint -restore or by adding suppress.lnt to the command line. This is useful for warnings that are always false in your firmware environment (e.g., unused parameter warnings for hardware callbacks).
  5. Document each suppression. Add a brief comment explaining why the warning is a false positive, e.g., //lint !e534: return value intentionally ignored for GPIO write. This helps future maintainers and auditors.
  6. Re-run PC-lint and verify. After adding suppressions, run lint again. Confirm the targeted warnings are gone and no new warnings appear. Check that the suppression did not accidentally hide a real issue on the same line.
  7. Review suppressions periodically. As code changes, some suppressions may become unnecessary. Use a lint option like -efile or a custom script to list all suppression comments and review them during code reviews.

Common Mistakes

  • Using -e (global suppress) when !e (single instance) is enough. This can hide real defects elsewhere in the file.
  • Suppressing a warning without understanding why it appears. Always investigate first; some warnings indicate real bugs.
  • Forgetting to restore after a block suppression, causing the suppression to leak into subsequent code.
  • Placing the comment on the wrong line. PC-lint associates the comment with the next line or the same line depending on syntax; test with a small example.
  • Using suppression files without version control. Keep them in the repository and review changes.

Tips

  • Prefer //lint !e for one-off cases and //lint -e inside a -save/-restore block for local groups.
  • Use //lint -esym to suppress warnings about specific symbols (e.g., -esym(534, write_register)) when the same function always triggers a false positive.
  • Keep a central suppression file for warnings that are inherent to your hardware abstraction layer, and document each entry.
  • Run lint with -w3 or higher to see all warnings, then suppress only the false ones. Do not lower the warning level globally.
  • Integrate lint into your build pipeline so suppressions are checked automatically.

Troubleshooting

If the warning persists after adding a suppression, check the comment syntax: PC-lint expects //lint with no space after the slashes. Ensure the comment is on the same line as the warning or on the line immediately preceding it, depending on the warning type. For block suppressions, verify that -save and -restore are correctly paired and that no other -e option overrides them. If you use a suppression file, confirm it is included in the lint command line and that the file path is correct. Also check that you are suppressing the correct warning number; some warnings have similar numbers (e.g., 534 vs. 534). Run lint with -v to see verbose output and confirm which options are active. If a suppression seems to hide a real warning, remove it and re-evaluate the code. Finally, ensure your lint version supports the suppression syntax you are using; older versions may require different comment styles.

Frequently Asked Questions

Can I suppress all warnings for a file?

Yes, use //lint -e* at the top of the file, but this is strongly discouraged as it hides all warnings. Prefer targeted suppressions.

What is the difference between !e and -e?

!e suppresses only the next occurrence of the warning; -e suppresses all occurrences in the current file or until restored.

How do I suppress a warning for a specific function only?

Use //lint -esym(534, function_name) to suppress warning 534 for that function across the project.

Will suppressions affect other files?

Inline suppressions affect only the file they are in. Suppressions in a configuration file affect all files that include that configuration.

Can I use PC-lint to list all active suppressions?

PC-lint does not have a built-in list command, but you can search your source files for //lint comments and your configuration files for -e options.

Is it safe to suppress warnings in safety-critical firmware?

Only after a thorough review and with clear documentation. Suppressions should be justified and periodically re-evaluated, especially for safety-critical code.