Fix write of 0 in '%c' (#6248) (#6249)

This commit is contained in:
Rodrigo Batista de Moraes 2025-08-01 02:54:18 -03:00 committed by GitHub
parent bd1ac03828
commit d0f0919830
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 5 additions and 5 deletions

View File

@ -206,6 +206,7 @@ Richard Myers
Risto Pejašinović Risto Pejašinović
Robert Balas Robert Balas
Robin Heinemann Robin Heinemann
Rodrigo Batista de Moraes
Rupert Swarbrick Rupert Swarbrick
Ryan Ziegler Ryan Ziegler
Ryszard Rozak Ryszard Rozak

View File

@ -746,10 +746,7 @@ string V3Number::displayed(FileLine* fl, const string& vformat) const VL_MT_STAB
if (width() > 8) if (width() > 8)
fl->v3warn(WIDTHTRUNC, "$display-like format of %c format of > 8 bit value"); fl->v3warn(WIDTHTRUNC, "$display-like format of %c format of > 8 bit value");
const unsigned int v = bitsValue(0, 8); const unsigned int v = bitsValue(0, 8);
char strc[2]; str.push_back(static_cast<char>(v));
strc[0] = v & 0xff;
strc[1] = '\0';
str = strc;
return str; return str;
} }
case 's': { case 's': {

View File

@ -16,7 +16,7 @@ test.compile()
test.execute() test.execute()
filename = test.obj_dir + "/zeros.log" filename = test.obj_dir + "/zeros.log"
if os.path.getsize(filename) != 16: if os.path.getsize(filename) != 20:
test.error(filename + ": Wrong file size") test.error(filename + ": Wrong file size")
test.passes() test.passes()

View File

@ -10,6 +10,8 @@ module t;
integer fd, cnt; integer fd, cnt;
initial begin initial begin
fd = $fopen({`STRINGIFY(`TEST_OBJ_DIR),"/zeros.log"}, "w"); fd = $fopen({`STRINGIFY(`TEST_OBJ_DIR),"/zeros.log"}, "w");
for (cnt = 0; cnt < 4; cnt = cnt + 1)
$fwrite(fd, "%c", 8'd0);
for (cnt = 0; cnt < 16; cnt = cnt + 4) for (cnt = 0; cnt < 16; cnt = cnt + 4)
$fwrite(fd, "%u", 32'd0); $fwrite(fd, "%u", 32'd0);
$fclose(fd); $fclose(fd);