The implementation of the test printing currently expects a null
terminated C-string. However, the `write_to_stderr` interface uses a
string view, which doesn't need to be null terminated. This patch
changes the printing interface to directly use `fwrite` instead rather
than relying on a null terminator.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/
D149493
void write_to_stderr(cpp::string_view msg) {
rpc::Port port = rpc::client.open(rpc::PRINT_TO_STDERR);
- port.send_n(msg.data(), msg.size() + 1);
+ port.send_n(msg.data(), msg.size());
port.close();
}
switch (port->get_opcode()) {
case __llvm_libc::rpc::Opcode::PRINT_TO_STDERR: {
- void *str = nullptr;
- port->recv_n([&](uint64_t size) { return str = malloc(size); });
- fputs(reinterpret_cast<char *>(str), stderr);
- free(str);
+ uint64_t str_size;
+ char *str = nullptr;
+ port->recv_n([&](uint64_t size) {
+ str_size = size;
+ str = new char[size];
+ return str;
+ });
+ fwrite(str, str_size, 1, stderr);
+ delete[] str;
break;
}
case __llvm_libc::rpc::Opcode::EXIT: {