diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-08-04 13:43:31 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-08-04 13:43:31 +0000 |
commit | ac4933548d5c76c12ffebbf85831e729b918792d (patch) | |
tree | 743756f6181694f1c3672ff411b92a55aae9f31e /tools/mpfrlint | |
parent | d7b1d1d292b031e01b03e5ca6149b2ebb15cd70c (diff) | |
download | mpfr-ac4933548d5c76c12ffebbf85831e729b918792d.tar.gz |
[tools/mpfrlint] Added a test detecting (unsafe) macros of the form:
#define FOO { ... }
The following form is preferred in most of the cases to avoid spurious
null statements:
#define FOO do { ... } while (0)
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@10725 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tools/mpfrlint')
-rwxr-xr-x | tools/mpfrlint | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/mpfrlint b/tools/mpfrlint index f25d84389..497ce57ff 100755 --- a/tools/mpfrlint +++ b/tools/mpfrlint @@ -185,6 +185,24 @@ do }' $file done +# Macros of the form: +# #define FOO { ... } +# may be unsafe and could yield obscure failures where writing "FOO;" as +# this is here a block followed by a null statement. The following form +# is preferred in most of the cases: +# #define FOO do { ... } while (0) +# so that "FOO;" is a single statement. +for file in $srctests +do + err-if-output "Missing 'do ... while (0)'" perl -e ' + while (<>) { + my $s = $_; + while ($s =~ s/\\\n//) { $s .= <> } + $s =~ /^#\s*define\s+\w+(\([^)]*\))?\s*{/ + and $s =~ tr/ \t/ /s, print "$ARGV: $s"; + }' $file +done + # Do not use snprintf as it is not available in ISO C90. # Even on platforms where it is available, the prototype # may not be included (e.g. with gcc -ansi), so that the |