From 3779776a39d81168b701b2cc2ce50a3b2331d3e8 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 4 Jun 2019 17:07:57 +0200 Subject: lib/clippy: error out on unsupported bits clippy can't process #ifdef or similar bits inside of an argument list (e.g. within the braces of a DEFUN or DEFPY statement.) Improve error reporting to catch these cases instead of generating broken C code. Fixes: #3840 Signed-off-by: David Lamparter --- python/clidef.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'python/clidef.py') diff --git a/python/clidef.py b/python/clidef.py index f8d96115bd..68682eea6c 100644 --- a/python/clidef.py +++ b/python/clidef.py @@ -183,11 +183,25 @@ argblock = Template(''' }''') def process_file(fn, ofd, dumpfd, all_defun): + errors = 0 filedata = clippy.parse(fn) for entry in filedata['data']: if entry['type'].startswith('DEFPY') or (all_defun and entry['type'].startswith('DEFUN')): + if len(entry['args'][0]) != 1: + sys.stderr.write('%s:%d: DEFPY function name not parseable (%r)\n' % (fn, entry['lineno'], entry['args'][0])) + errors += 1 + continue + cmddef = entry['args'][2] + for i in cmddef: + if not (i.startswith('"') and i.endswith('"')): + sys.stderr.write('%s:%d: DEFPY command string not parseable (%r)\n' % (fn, entry['lineno'], cmddef)) + errors += 1 + cmddef = None + break + if cmddef is None: + continue cmddef = ''.join([i[1:-1] for i in cmddef]) graph = clippy.Graph(cmddef) @@ -251,6 +265,8 @@ def process_file(fn, ofd, dumpfd, all_defun): params['nonempty'] = len(argblocks) ofd.write(templ.substitute(params)) + return errors + if __name__ == '__main__': import argparse @@ -274,7 +290,9 @@ if __name__ == '__main__': if args.show: dumpfd = sys.stderr - process_file(args.cfile, ofd, dumpfd, args.all_defun) + errors = process_file(args.cfile, ofd, dumpfd, args.all_defun) + if errors != 0: + sys.exit(1) if args.o is not None: clippy.wrdiff(args.o, ofd, [args.cfile, os.path.realpath(__file__), sys.executable]) -- cgit v1.2.3