Mercurial > hg-stable
changeset 28594:d3990da51637
check-code: prevent use of strcpy
author | Augie Fackler <augie@google.com> |
---|---|
date | Sat, 19 Mar 2016 20:18:38 -0400 |
parents | e60c492a0d9b |
children | adda6dee600e |
files | contrib/check-code.py tests/test-contrib-check-code.t |
diffstat | 2 files changed, 17 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/check-code.py Sat Mar 19 20:02:19 2016 -0400 +++ b/contrib/check-code.py Sat Mar 19 20:18:38 2016 -0400 @@ -359,6 +359,7 @@ (r'^#\s+\w', "use #foo, not # foo"), (r'[^\n]\Z', "no trailing newline"), (r'^\s*#import\b', "use only #include in standard C code"), + (r'strcpy\(', "don't use strcpy, use strlcpy or memcpy"), ], # warnings []
--- a/tests/test-contrib-check-code.t Sat Mar 19 20:02:19 2016 -0400 +++ b/tests/test-contrib-check-code.t Sat Mar 19 20:18:38 2016 -0400 @@ -69,6 +69,22 @@ dict() is different in Py2 and 3 and is slower than {} [1] + $ cat > foo.c <<EOF + > void narf() { + > strcpy(foo, bar); + > // strcpy_s is okay, but this comment is not + > strcpy_s(foo, bar); + > } + > EOF + $ "$check_code" ./foo.c + ./foo.c:2: + > strcpy(foo, bar); + don't use strcpy, use strlcpy or memcpy + ./foo.c:3: + > // strcpy_s is okay, but this comment is not + don't use //-style comments + [1] + $ cat > is-op.py <<EOF > # is-operator comparing number or string literal > x = None