diff --git a/enforce_not_null.py b/enforce_not_null.py new file mode 100644 index 00000000000..3e00b4eb212 --- /dev/null +++ b/enforce_not_null.py @@ -0,0 +1,45 @@ +import os +import re + +def find_s2n_config_new_calls(directory): + # Define the regex pattern for s2n_config_new() function call + config_new = re.compile(r'\bstruct s2n_config *(.*) = s2n_config_new\s*\(') + + NULL_CHECKS = [ + "RESULT_ENSURE_REF(<>)", + "POSIX_ENSURE_REF(<>)", + "EXPECT_NOT_NULL(<>)", + ] + # List to store file paths with matching lines + matching_files = [] + + # Iterate through each file in the directory and its subdirectories + for root, dirs, files in os.walk(directory): + for file in files: + if file.endswith(".c"): + file_path = os.path.join(root, file) + + # Open the file and read its content + with open(file_path, 'r', encoding='utf-8', errors='ignore') as f: + lines = f.readlines() + + results = [] + for line_number, line in enumerate(lines, start=1): + match = config_new.search(line) + if match == None: + continue + variable = match.group(1) + print(variable) + print(line.strip()) + matching_files.append((file_path, line_number, line.strip())) + return matching_files + +# Replace 'your_codebase_directory' with the actual path to your C codebase +codebase_directory = '.' + +# Find s2n_config_new() calls in the codebase +result = find_s2n_config_new_calls(codebase_directory) + +# Display the results +# for file_path, line_number, line_content in result: +# print(f"File: {file_path}:{line_number}: {line_content}")