On Fri, Oct 26, 2018 at 04:26:32PM +0100, Ben Dooks wrote: > --- > evaluate.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 157 insertions(+), 1 deletion(-) > > diff --git a/evaluate.c b/evaluate.c > index b96696d..82ddf9f 100644 > --- a/evaluate.c > +++ b/evaluate.c > @@ -2243,11 +2243,154 @@ static struct symbol *evaluate_alignof(struct expression *expr) > return size_t_ctype; > } > > +static int decompose_format_printf(const char *string, struct symbol **result) > +{ > + int count = 0; > + > + for (; string[0] != '\0'; string++) { > + if (string[0] == '%') { I would prefer to write this like: struct symbol *sym = NULL; int len = 0; if (string[0] == '%') continue; ... to spare one indentation but it's not really important. > +static int evaluate_format_printf(struct symbol *fn, struct expression *expr, struct symbol ***result) > +{ > + const char *fmt_string = NULL; > + > + if (!expr) > + return -1; > + if (expr->string && expr->string->length) > + fmt_string = expr->string->data; > + if (!fmt_string) { > + struct symbol *sym = evaluate_expression(expr); > + > + /* attempt to find initialiser for this */ > + if (sym && sym->initializer && sym->initializer->string) > + fmt_string = sym->initializer->string->data; > + } > + > + if (fmt_string) { > + struct symbol **syms = NULL; > + int count; > + > + count = decompose_format_printf(fmt_string, NULL); > + if (count <= 0) > + return count; > + > + syms = calloc(sizeof(struct symbol *), count); Sparse make heavy use of pointer lists and I think it better/easier to use them here too instead of parsing the string twice and using calloc/free. -- Luc