diff --git a/main.c b/main.c index 0c60b86d..4f070acc 100644 --- a/main.c +++ b/main.c @@ -66,7 +66,7 @@ extern int protect_args; extern int relative_paths; extern int sanitize_paths; extern int curr_dir_depth; -extern int curr_dir_len; +extern unsigned int curr_dir_len; extern int module_id; extern int rsync_port; extern int whole_file; diff --git a/packaging/var-checker b/packaging/var-checker index f17c69a2..2b9cc8e5 100755 --- a/packaging/var-checker +++ b/packaging/var-checker @@ -6,9 +6,10 @@ import os, sys, re, argparse, glob -VARS_RE = re.compile(r'^(?!(?:extern|enum)\s)([a-zA-Z]\S*\s+.*);', re.M) +VARS_RE = re.compile(r'^(?!(?:extern|enum)\s)([a-zA-Z][^ \n\t:]*\s+.*);', re.M) EXTERNS_RE = re.compile(r'^extern\s+(.*);', re.M) +types = { } sizes = { } def main(): @@ -68,19 +69,46 @@ def parse_vars(fn, lines): for line in lines: line = re.sub(r'\s*\{.*\}', '', line) line = re.sub(r'\s*\(.*\)', '', line) - for item in re.split(r'\s*,\s*', line): - item = re.sub(r'\s*=.*', '', item) - m = re.search(r'(?P\w+)(?P\[.*?\])?$', item) + line = re.sub(r'\s*=\s*[^,]*', '', line) + m = re.search(r'^(?:(?:static|extern)\s+)?(?P[^\[,]+?)(?P\w+([\[,].+)?)$', line) + if not m: + print(f"Bogus match? ({line})") + continue + items = m['vars'] + main_type = m['type'].strip() + mt_len = len(main_type) + main_type = main_type.rstrip('*') + first_stars = '*' * (mt_len - len(main_type)) + if first_stars: + main_type = main_type.rstrip() + items = first_stars + items + for item in re.split(r'\s*,\s*', items): + m = re.search(r'(?P\*+\s*)?(?P\w+)(?P\[.*?\])?$', item) if not m: print(f"Bogus match? ({item})") continue - if m['sz']: - if m['var'] in sizes: - if sizes[m['var']] != m['sz']: + typ = main_type + if m['stars']: + typ = typ + m['stars'].strip() + chk = [ + 'type', typ, types, + 'size', m['sz'], sizes, + ] + while chk: + label = chk.pop(0) + new = chk.pop(0) + lst = chk.pop(0) + if not new: + continue + if label == 'type': + new = ' '.join(new.split()).replace(' *', '*') + if m['var'] in lst: + old = lst[m['var']] + if new != old: var = m['var'] - print(fn, f'has inconsistent size for "{var}":', m['sz'], 'vs', sizes[var]) + print(fn, f'has inconsistent {label} for "{var}":', new, 'vs', old) else: - sizes[m['var']] = m['sz'] + lst[m['var']] = new ret.append(m['var']) return ret diff --git a/t_stub.c b/t_stub.c index 085378a8..eee92729 100644 --- a/t_stub.c +++ b/t_stub.c @@ -28,7 +28,7 @@ int preallocate_files = 0; int protect_args = 0; int module_id = -1; int relative_paths = 0; -int module_dirlen = 0; +unsigned int module_dirlen = 0; int preserve_xattrs = 0; int preserve_perms = 0; int preserve_executability = 0;