Page MenuHomePhabricator

[LINTER] build: Add linter for checking accidental locale dependence
ClosedPublic

Authored by Fabien on Mar 18 2019, 15:27.

Details

Summary
This linter will check for code accidentally introducing locale
dependencies.

Unnecessary locale dependence can cause bugs that are very tricky to
isolate and fix. We should avoid using locale dependent functions if
possible.

Backport of core PR13041

There are several differences from the original PR:

  • Updated shebang to /usr/bin/env bash.
  • Remove known violations that don't exist in our codebase.
  • Allow for fprintf. Core only allows it if it targets stdout or

stderr, but the original regex is inefficient due to our code
formatting. As there currently is a single occurence which doesn't match
the rule (and is safe because it only outputs digits), then I choose to
ignore it at the moment. It can be reworked later if needed.

  • Make the script run from everywhere in the source tree (note the

:/ notation in the git grep call).

  • Fix a bug: grep'ing for strtol will shadow strtoll, the same

with strtoul and strtoull. Appending an opening parenthesis to
grep for strtol( instead fixes the issue. A comment is added to
explain the meaning of the parenthesis.

  • Exclude the seeder from the linter.
  • Include changes from PR14115 to fix a BSD grep issue with empty

subexpressions

Test Plan

Should return no error (no output):

./test/lint/lint-locale-dependence.sh

Comment any of the known exception then run:

./test/lint/lint-locale-dependence.sh

and check the errors are reported.

Diff Detail

Repository
rABC Bitcoin ABC
Branch
PR13041
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 5243
Build 8549: Bitcoin ABC Buildbot (legacy)
Build 8548: arc lint + arc unit

Event Timeline

Rebase and include fix from PR14115

This revision is now accepted and ready to land.Mar 19 2019, 16:45