From 4ddf234c324603d7a2882fca82f6d1fd5c0bbbf7 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 1 Jan 2023 18:46:17 -0800 Subject: [PATCH] vvp: Remove null-bytes when converting string literals to SV strings The `%pushi/str` and `%concati/str` instructions should remove null-bytes from the string literal when converting it to a string. This is defined in section 6.16 ("String data type") of the LRM (1800-2017). This is already handled correctly when converting a vector from the stack to a SV string, just not when converting a string literal to SV string. Signed-off-by: Lars-Peter Clausen --- vvp/vthread.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vvp/vthread.cc b/vvp/vthread.cc index 135b20ea9..2b35315b0 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -399,7 +399,11 @@ static string filter_string(const char*text) cnt -= 1; ptr += 1; } - tmp[dst++] = byte; + + // null-bytes are supposed to be removed when assigning a string + // literal to a string. + if (byte != '\0') + tmp[dst++] = byte; // After the while loop above, the ptr points to the next character, // but the for-loop condition is assuming that ptr points to the last