qerror: qerror_format(): return an allocated string
Simplifies current and future users. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
5f0f0e13e1
commit
2b38cf2e03
5
error.c
5
error.c
@ -65,10 +65,7 @@ bool error_is_set(Error **errp)
|
|||||||
const char *error_get_pretty(Error *err)
|
const char *error_get_pretty(Error *err)
|
||||||
{
|
{
|
||||||
if (err->msg == NULL) {
|
if (err->msg == NULL) {
|
||||||
QString *str;
|
err->msg = qerror_format(err->fmt, err->obj);
|
||||||
str = qerror_format(err->fmt, err->obj);
|
|
||||||
err->msg = g_strdup(qstring_get_str(str));
|
|
||||||
QDECREF(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err->msg;
|
return err->msg;
|
||||||
|
10
qerror.c
10
qerror.c
@ -493,9 +493,11 @@ static QString *qerror_format_desc(QDict *error,
|
|||||||
return qstring;
|
return qstring;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString *qerror_format(const char *fmt, QDict *error)
|
char *qerror_format(const char *fmt, QDict *error)
|
||||||
{
|
{
|
||||||
const QErrorStringTable *entry = NULL;
|
const QErrorStringTable *entry = NULL;
|
||||||
|
QString *qstr;
|
||||||
|
char *ret;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; qerror_table[i].error_fmt; i++) {
|
for (i = 0; qerror_table[i].error_fmt; i++) {
|
||||||
@ -505,7 +507,11 @@ QString *qerror_format(const char *fmt, QDict *error)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return qerror_format_desc(error, entry);
|
qstr = qerror_format_desc(error, entry);
|
||||||
|
ret = g_strdup(qstring_get_str(qstr));
|
||||||
|
QDECREF(qstr);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
2
qerror.h
2
qerror.h
@ -34,7 +34,7 @@ QString *qerror_human(const QError *qerror);
|
|||||||
void qerror_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
|
void qerror_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
|
||||||
void qerror_report_err(Error *err);
|
void qerror_report_err(Error *err);
|
||||||
void assert_no_error(Error *err);
|
void assert_no_error(Error *err);
|
||||||
QString *qerror_format(const char *fmt, QDict *error);
|
char *qerror_format(const char *fmt, QDict *error);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* QError class list
|
* QError class list
|
||||||
|
Loading…
x
Reference in New Issue
Block a user