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ć
Robert Balas
Robin Heinemann
Rodrigo Batista de Moraes
Rupert Swarbrick
Ryan Ziegler
Ryszard Rozak

View File

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

View File

@ -16,7 +16,7 @@ test.compile()
test.execute()
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.passes()

View File

@ -10,6 +10,8 @@ module t;
integer fd, cnt;
initial begin
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)
$fwrite(fd, "%u", 32'd0);
$fclose(fd);