From e073377e9bb81c1a9c6d9697beeebff909c3bbd3 Mon Sep 17 00:00:00 2001 From: id_pschernig Date: Wed, 22 Oct 2025 16:12:24 +0200 Subject: [PATCH 1/2] Fix problem with calculation of the 'c_ast.FuncDecl' offset --- nala/dist/nala.c | 6 +++--- nala/inspect.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/nala/dist/nala.c b/nala/dist/nala.c index f24c78d..ff7908d 100644 --- a/nala/dist/nala.c +++ b/nala/dist/nala.c @@ -3360,7 +3360,7 @@ void nala_subprocess_result_free(struct nala_subprocess_result_t *self_p) // #include "subprocess.h" -#define DEPTH_MAX 100 +#define NALA_DEPTH_MAX 100 #define ANSI_COLOR_GREEN "\x1b[32m" #define ANSI_COLOR_CYAN "\x1b[36m" @@ -3603,9 +3603,9 @@ char *nala_traceback_string(const char *prefix_p, void *arg_p) { int depth; - void *addresses[DEPTH_MAX]; + void *addresses[NALA_DEPTH_MAX]; - depth = backtrace(&addresses[0], DEPTH_MAX); + depth = backtrace(&addresses[0], NALA_DEPTH_MAX); return (nala_traceback_format(addresses, depth, diff --git a/nala/inspect.py b/nala/inspect.py index b26ecc0..2d56946 100644 --- a/nala/inspect.py +++ b/nala/inspect.py @@ -390,6 +390,16 @@ def parse(self): self.typedefs_code + self.structs_code + self.func_signatures) self.file_ast = self.cparser.parse(code) func_offset = len(self.typedefs_code + self.structs_code) + # PATCH BEGIN + # The above offset calculation sometimes doesn't point to the first element of + # type 'c_ast.FuncDecl'. In that case we use the below search to find the first + # 'c_ast.FuncDecl' and take this index as offset. + if not isinstance(self.file_ast.ext[func_offset].type, c_ast.FuncDecl): + for i in range(len(self.file_ast.ext)): + if isinstance(self.file_ast.ext[i].type, c_ast.FuncDecl): + func_offset = i + break + # PATCH END for i, func_name in enumerate(self.func_names, func_offset): if self.param_names is None: From 897818fb106cbcfdcbe4d87a67b1e199e8713c43 Mon Sep 17 00:00:00 2001 From: id_pschernig Date: Thu, 23 Oct 2025 09:37:46 +0200 Subject: [PATCH 2/2] Fix problem with calculation of the 'c_ast.FuncDecl' offset in cases where function pointer typedefs are present in the translation unit. --- nala/inspect.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/nala/inspect.py b/nala/inspect.py index 2d56946..449fcf9 100644 --- a/nala/inspect.py +++ b/nala/inspect.py @@ -391,11 +391,15 @@ def parse(self): self.file_ast = self.cparser.parse(code) func_offset = len(self.typedefs_code + self.structs_code) # PATCH BEGIN - # The above offset calculation sometimes doesn't point to the first element of - # type 'c_ast.FuncDecl'. In that case we use the below search to find the first - # 'c_ast.FuncDecl' and take this index as offset. + # The above offset calculation sometimes ends up giving a wrong start index. + # As a result the first function_declaration handed over to `rename_parameters` + # is of type 'Struct' which has no argument 'args'! + # Now we test if the element at index `func_offset` has the correct type, and if + # not the AST list is searched for the first 'c_ast.FuncDecl' starting from the + # calculated `func_offset`. The index of the first detected 'c_ast.FuncDecl' is + # then used as new `func_offset`! if not isinstance(self.file_ast.ext[func_offset].type, c_ast.FuncDecl): - for i in range(len(self.file_ast.ext)): + for i in range(func_offset, len(self.file_ast.ext)): if isinstance(self.file_ast.ext[i].type, c_ast.FuncDecl): func_offset = i break