Skip to content

Commit b743845

Browse files
elmarcobonzini
authored andcommitted
mips: fix potential fopen(NULL,...)
Spotted thanks to ASAN. Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 6b2fef7 commit b743845

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

hw/nvram/ds1225y.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static int nvram_post_load(void *opaque, int version_id)
8080
}
8181

8282
/* Write back nvram contents */
83-
s->file = fopen(s->filename, "wb");
83+
s->file = s->filename ? fopen(s->filename, "wb") : NULL;
8484
if (s->file) {
8585
/* Write back contents, as 'wb' mode cleaned the file */
8686
if (fwrite(s->contents, s->chip_size, 1, s->file) != 1) {
@@ -126,7 +126,7 @@ static int nvram_sysbus_initfn(SysBusDevice *dev)
126126
sysbus_init_mmio(dev, &s->iomem);
127127

128128
/* Read current file */
129-
file = fopen(s->filename, "rb");
129+
file = s->filename ? fopen(s->filename, "rb") : NULL;
130130
if (file) {
131131
/* Read nvram contents */
132132
if (fread(s->contents, s->chip_size, 1, file) != 1) {

0 commit comments

Comments
 (0)