Skip to content

Commit dd33aa6

Browse files
authored
Fix environ_get: append null. (#137)
Signed-off-by: Takeshi Yoneda <[email protected]>
1 parent d83a60f commit dd33aa6

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/exports.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ Word wasi_unstable_environ_get(void *raw_context, Word environ_array_ptr, Word e
781781
data.append(e.first);
782782
data.append("=");
783783
data.append(e.second);
784-
data.append("\x0");
784+
data.append({0x0});
785785
if (!context->wasmVm()->setMemory(environ_buf, data.size(), data.c_str())) {
786786
return 21; // __WASI_EFAULT
787787
}

test/exports_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ TEST_P(TestVM, Environment) {
6767
run(current_context_);
6868

6969
auto msg = context.log_msg();
70-
EXPECT_NE(std::string::npos, msg.find("KEY1: VALUE1")) << msg;
71-
EXPECT_NE(std::string::npos, msg.find("KEY2: VALUE2")) << msg;
70+
EXPECT_NE(std::string::npos, msg.find("KEY1: VALUE1\n")) << msg;
71+
EXPECT_NE(std::string::npos, msg.find("KEY2: VALUE2\n")) << msg;
7272
}
7373

7474
TEST_P(TestVM, WithoutEnvironment) {

test/test_data/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ pub extern "C" fn run() {
2323
__wasilibc_initialize_environ();
2424
}
2525
for (key, value) in std::env::vars() {
26-
println!("{}: {}", key, value);
26+
println!("{}: {}\n", key, value);
2727
}
2828
}

0 commit comments

Comments
 (0)