y2038.py: some fixes for obsolete code in y2038.py (#5131)

This commit is contained in:
Daniel Marjamäki 2023-06-08 14:44:05 +02:00 committed by GitHub
parent be2824b003
commit 520a6644a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 15 deletions

View File

@ -9,10 +9,9 @@
# 3. Any Y2038-unsafe symbol when _USE_TIME_BITS64 is not defined.
#
# Example usage:
# $ cppcheck --dump path-to-src/test.c
# $ y2038.py path-to-src/test.c.dump
# $ cppcheck --addon=y2038 path-to-src/test.c
#
# y2038.py will walk the source tree for .dump files.
from __future__ import print_function
import cppcheckdata
@ -156,22 +155,14 @@ def check_y2038_safe(dumpfile, quiet=False):
# load XML from .dump file
data = cppcheckdata.CppcheckData(dumpfile)
# Convert dump file path to source file in format generated by cppcheck.
# For example after the following call:
# cppcheck ./src/my-src.c --dump
# We got 'src/my-src.c' value for 'file' field in cppcheckdata.
srcfile = dumpfile.rstrip('.dump')
srcfile = os.path.expanduser(srcfile)
srcfile = os.path.normpath(srcfile)
# go through each configuration
srcfile = data.files[0]
for cfg in data.iterconfigurations():
if not quiet:
print('Checking %s, config %s...' % (srcfile, cfg.name))
safe_ranges = []
safe = -1
time_bits_defined = False
srclinenr = '0'
srclinenr = 0
for directive in cfg.directives:
# track source line number
@ -236,7 +227,7 @@ if __name__ == '__main__':
args = parser.parse_args()
exit_code = 0
quiet = not any((args.quiet, args.cli))
quiet = args.quiet or args.cli
if not args.dumpfile:
if not args.quiet:
@ -244,7 +235,7 @@ if __name__ == '__main__':
sys.exit(0)
for dumpfile in args.dumpfile:
if not args.quiet:
if not quiet:
print('Checking ' + dumpfile + '...')
check_y2038_safe(dumpfile, quiet)