Skip to content

Commit

Permalink
Merge pull request #197 from dpogue/ungetc
Browse files Browse the repository at this point in the history
Replace fputc with ungetc to fix UB
  • Loading branch information
zrax authored Oct 1, 2024
2 parents cea730a + 1309c84 commit 4f51cb0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Tests/Test_EncryptedStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ TEST_CASE("EncryptedStream known values", "[streams]")
REQUIRE(stream.getEncType() == DS::EncryptedStream::Type::e_xxtea);
REQUIRE(stream.size() == resultsz);

REQUIRE_FALSE(stream.atEof());

char test[sizeof(result)];
stream.readBytes(test, resultsz);
test[sizeof(test) - 1] = 0;
Expand All @@ -59,6 +61,8 @@ TEST_CASE("EncryptedStream known values", "[streams]")
REQUIRE(stream.getEncType() == DS::EncryptedStream::Type::e_tea);
REQUIRE(stream.size() == resultsz);

REQUIRE_FALSE(stream.atEof());

char test[sizeof(result)];
stream.readBytes(test, resultsz);
test[sizeof(test) - 1] = 0;
Expand Down
2 changes: 1 addition & 1 deletion streams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ uint32_t DS::FileStream::size() const
bool DS::FileStream::atEof()
{
int ch = fgetc(m_file);
fputc(ch, m_file);
ungetc(ch, m_file);
return (ch == EOF);
}

Expand Down

0 comments on commit 4f51cb0

Please sign in to comment.