From 06101b631624bac74ae8f9aff261d6bf4faa8a08 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Mon, 16 Mar 2026 11:54:55 +0000 Subject: [PATCH] print: add nullptr handling --- mie/print/op.c | 17 +++++++++++++---- mie/print/type.c | 5 +++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/mie/print/op.c b/mie/print/op.c index 5977684..95cd306 100644 --- a/mie/print/op.c +++ b/mie/print/op.c @@ -38,6 +38,10 @@ void mie_printer_print_op_arg( b_stream_write_char(printer->p_stream, '%'); } + if (!arg_name) { + arg_name = ""; + } + b_stream_write_string(printer->p_stream, arg_name, NULL); if (!resolved @@ -62,15 +66,20 @@ void mie_printer_print_op_successor( b_stream_write_char(printer->p_stream, '^'); bool resolved = false; + const char *name = NULL; if (successor->s_flags & MIE_OP_F_SUCCESSOR_RESOLVED) { - b_stream_write_string( - printer->p_stream, successor->s_block->b_name.n_str, NULL); + name = successor->s_block->b_name.n_str; resolved = true; } else { - b_stream_write_string( - printer->p_stream, successor->s_block_name, NULL); + name = successor->s_block_name; } + if (!name) { + name = ""; + } + + b_stream_write_string(printer->p_stream, name, NULL); + if (!resolved && MIE_TEST_FLAGS( printer->p_flags, MIE_PRINT_F_MARK_UNRESOLVED_ELEMENTS)) { diff --git a/mie/print/type.c b/mie/print/type.c index bb5e60c..96fcef1 100644 --- a/mie/print/type.c +++ b/mie/print/type.c @@ -12,6 +12,11 @@ void mie_printer_print_type(struct mie_printer *printer, const struct mie_type *type) { + if (!type) { + b_stream_write_string(printer->p_stream, "", NULL); + return; + } + if (TYPE_HAS_PRINT_CALLBACK(type)) { type->ty_def->ty_print(type, printer); } else if (TYPE_IS_BUILTIN(type)) {