Skip to content

Commit 29549c3

Browse files
jhuber6yuxuanchen1997
authored andcommitted
[libc] Fix GPU 'printf' on strings with padding
Summary: We get the `strlen` to know how much memory to allocate here, but it wasn't taking into account if the padding was larger than the string itself. This patch sets it to an empty string so we always add the minimum size. This implementation is slightly wasteful with memory, but I am not concerned with a few extra bytes here and there for some memory that gets immediately free'd. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251420
1 parent 00458de commit 29549c3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

libc/utils/gpu/server/rpc_server.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ void handle_printf(rpc::Server::Port &port) {
108108
if (cur_section.has_conv && cur_section.conv_name == 's' &&
109109
cur_section.conv_val_ptr) {
110110
strs_to_copy[lane].emplace_back(cur_section.conv_val_ptr);
111+
// Get the minimum size of the string in the case of padding.
112+
char c = '\0';
113+
cur_section.conv_val_ptr = &c;
114+
convert(&writer, cur_section);
111115
} else if (cur_section.has_conv) {
112116
// Ignore conversion errors for the first pass.
113117
convert(&writer, cur_section);

0 commit comments

Comments
 (0)