HomePhabricator

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

Description

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

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.

Reviewers: #bitcoin_abc, deadalnix, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Subscribers: teamcity, schancel

Differential Revision: https://reviews.bitcoinabc.org/D2698

Details

Provenance
practicalswift <practicalswift@users.noreply.github.com>Authored on Apr 20 2018, 12:12
FabienCommitted on Mar 20 2019, 13:47
FabienPushed on Mar 20 2019, 13:47
Reviewer
Restricted Project
Differential Revision
D2698: [LINTER] build: Add linter for checking accidental locale dependence
Parents
rABCa423ecd14cd9: [CMAKE] Harden the executables
Branches
Unknown
Tags
Unknown

Event Timeline