> Subject: [Qemu-devel] [PATCH v3 08/10] qtest: check the value returned by > fopen() > > The function fopen() may fail, so check its return value. > > Signed-off-by: zhanghailiang <zhang.zhanghaili...@huawei.com> > Signed-off-by: Li Liu <john.li...@huawei.com> > --- > qtest.c | 5 +++++ > tests/bios-tables-test.c | 2 ++ > 2 files changed, 7 insertions(+) > > diff --git a/qtest.c b/qtest.c > index 04a6dc1..ae9b636 100644 > --- a/qtest.c > +++ b/qtest.c > @@ -536,6 +536,11 @@ void qtest_init(const char *qtest_chrdev, const char > *qtest_log, Error **errp) > if (qtest_log) { > if (strcmp(qtest_log, "none") != 0) { > qtest_log_fp = fopen(qtest_log, "w+"); > + if (qtest_log_fp == NULL) { > + error_setg(errp, "Failed to open log file for qtest: \"%s\"", > + qtest_log); > + return; > + }
Actually I don't think this check is necessary, because the qtest_log_fp will be checked where it is used. Best regards, -Gonglei > } > } else { > qtest_log_fp = stderr; > diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c > index 045eb27..6a357c0 100644 > --- a/tests/bios-tables-test.c > +++ b/tests/bios-tables-test.c > @@ -790,6 +790,8 @@ int main(int argc, char *argv[]) > const char *arch = qtest_get_arch(); > FILE *f = fopen(disk, "w"); > int ret; > + > + g_assert(f != NULL); > fwrite(boot_sector, 1, sizeof boot_sector, f); > fclose(f); > > -- > 1.7.12.4 > >