Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor code defects #176

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/parser/WASMParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,11 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate {
}

m_vmStack.push_back(VMStackInfo(*this, type, pos, m_functionStackSizeSoFar, localIndex));
m_functionStackSizeSoFar += Walrus::valueStackAllocatedSize(type);
if (UNLIKELY(m_functionStackSizeSoFar > std::numeric_limits<Walrus::ByteCodeStackOffset>::max())) {
size_t allocSize = Walrus::valueStackAllocatedSize(type);
if (UNLIKELY(m_functionStackSizeSoFar + allocSize > std::numeric_limits<Walrus::ByteCodeStackOffset>::max())) {
throw std::string("too many stack usage. we could not support this(yet).");
}
m_functionStackSizeSoFar += allocSize;
m_currentFunction->m_requiredStackSize = std::max(
m_currentFunction->m_requiredStackSize, m_functionStackSizeSoFar);
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Memory::Memory(uint64_t initialSizeInByte, uint64_t maximumSizeInByte)
, m_maximumSizeInByte(maximumSizeInByte)
, m_buffer(nullptr)
{
RELEASE_ASSERT(initialSizeInByte <= std::numeric_limits<size_t>::max());
ASSERT(initialSizeInByte <= std::numeric_limits<size_t>::max());
#if defined(WALRUS_USE_MMAP)
if (m_maximumSizeInByte) {
#ifndef WALRUS_32_MEMORY_INITIAL_MMAP_RESERVED_ADDRESS_SIZE
Expand Down
7 changes: 4 additions & 3 deletions src/shell/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,9 @@ static void executeWAST(Store* store, const std::string& filename, const std::ve
auto result = wabt::ParseWastScript(lexer.get(), &script, &errors, &parse_wast_options);
if (!wabt::Succeeded(result)) {
printf("Syntax error(s):\n");
for (auto e : errors)
for (auto& e : errors) {
printf(" %s\n", e.message.c_str());
}
printf("\n");
RELEASE_ASSERT_NOT_REACHED();
}
Expand Down Expand Up @@ -1000,15 +1001,15 @@ int main(int argc, char* argv[])
FILE* fp = fopen(filePath.data(), "r");
if (fp) {
fseek(fp, 0, SEEK_END);
auto sz = ftell(fp);
size_t sz = ftell(fp);
fseek(fp, 0, SEEK_SET);
std::vector<uint8_t> buf;
buf.resize(sz);
int ret = fread(buf.data(), 1, sz, fp);
fclose(fp);
// read again with binary mode if result is not success
// this one needs for windows
if (ret != sz) {
if (UNLIKELY((size_t)ret != sz)) {
FILE* fp = fopen(filePath.data(), "rb");
fread(buf.data(), sz, 1, fp);
fclose(fp);
Expand Down