Skip to content

Commit 741feeb

Browse files
committed
Move checks in palette load/save
1 parent 1a10340 commit 741feeb

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/ArchivItem_Palette.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ int libsiedler2::ArchivItem_Palette::load(std::istream& file, bool skip)
4949
}
5050

5151
static_assert(sizeof(colors) == 256u * 3u, "Color array has alignment. Cannot read it in whole");
52-
fs.read(&colors[0].r, sizeof(colors));
52+
if(!fs.read(&colors[0].r, sizeof(colors)))
53+
return ErrorCode::UNEXPECTED_EOF;
5354

5455
setDefaultTransparentIdx();
5556

56-
return (!file) ? ErrorCode::UNEXPECTED_EOF : ErrorCode::NONE;
57+
return ErrorCode::NONE;
5758
}
5859

5960
/**
@@ -74,9 +75,8 @@ int libsiedler2::ArchivItem_Palette::write(std::ostream& file, bool skip) const
7475
fs << int16_t(256);
7576

7677
static_assert(sizeof(colors) == 256u * 3u, "Color array has alignment. Cannot write it in whole");
77-
fs.write(&colors[0].r, sizeof(colors));
7878

79-
return (!file) ? ErrorCode::UNEXPECTED_EOF : ErrorCode::NONE;
79+
return fs.write(&colors[0].r, sizeof(colors)) ? ErrorCode::NONE : ErrorCode::UNEXPECTED_EOF;
8080
}
8181

8282
/**

0 commit comments

Comments
 (0)