From: Paolo Bonzini Date: Wed, 28 May 2025 12:27:47 +0000 (+0200) Subject: util/error: make func optional X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e8fb9c91a3ea437bdddd1819e180f36112e41ae1;p=thirdparty%2Fqemu.git util/error: make func optional The function name is not available in Rust, so make it optional. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- diff --git a/include/qapi/error-internal.h b/include/qapi/error-internal.h index 1ec3ceb40f..ff18a2086d 100644 --- a/include/qapi/error-internal.h +++ b/include/qapi/error-internal.h @@ -18,6 +18,8 @@ struct Error { char *msg; ErrorClass err_class; + + /* Used for error_abort only, may be NULL. */ const char *func; /* diff --git a/util/error.c b/util/error.c index 3449ecc0b9..daea2142f3 100644 --- a/util/error.c +++ b/util/error.c @@ -24,8 +24,13 @@ Error *error_warn; static void error_handle(Error **errp, Error *err) { if (errp == &error_abort) { - fprintf(stderr, "Unexpected error in %s() at %.*s:%d:\n", - err->func, err->src_len, err->src, err->line); + if (err->func) { + fprintf(stderr, "Unexpected error in %s() at %.*s:%d:\n", + err->func, err->src_len, err->src, err->line); + } else { + fprintf(stderr, "Unexpected error at %.*s:%d:\n", + err->src_len, err->src, err->line); + } error_report("%s", error_get_pretty(err)); if (err->hint) { error_printf("%s", err->hint->str);