tests/bios-tables-test: check the value returned by fopen()
authorzhanghailiang <zhang.zhanghailiang@huawei.com>
Mon, 18 Aug 2014 07:54:33 +0000 (15:54 +0800)
committerMichael Tokarev <mjt@tls.msk.ru>
Sun, 24 Aug 2014 09:16:32 +0000 (13:16 +0400)
The function fopen() may fail, so check its return value.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Signed-off-by: Li Liu <john.liuli@huawei.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
tests/bios-tables-test.c

index 045eb27577b5126a828b5f298a6b98c91ce104e2..602932b888a946d13a82210f1b1a228f0866b11d 100644 (file)
@@ -790,6 +790,11 @@ int main(int argc, char *argv[])
     const char *arch = qtest_get_arch();
     FILE *f = fopen(disk, "w");
     int ret;
+
+    if (!f) {
+        fprintf(stderr, "Couldn't open \"%s\": %s", disk, strerror(errno));
+        return 1;
+    }
     fwrite(boot_sector, 1, sizeof boot_sector, f);
     fclose(f);