Skip to content

Commit

Permalink
Conversion specification should start with %
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed May 23, 2021
1 parent cabd277 commit 5d29bec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/rt/rtkern.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,10 +1013,14 @@ struct uarray _std_to_string_real_format(double value, struct uarray *format)
else
str_len = format->dims[0].left - format->dims[0].right + 1;

char *LOCAL fmt_str = xmalloc(str_len + 2);
fmt_str[0] = '%';
memcpy(fmt_str + 1, format->ptr, str_len);
fmt_str[str_len + 1] = '\0';
char *LOCAL fmt_str = xmalloc(str_len + 1);
memcpy(fmt_str, format->ptr, str_len);
fmt_str[str_len] = '\0';

if (fmt_str[0] != '%') {
rt_show_trace(NULL);
fatal("conversion specification must start with '%%'");
}

for (const char *p = fmt_str + 1; *p; p++) {
switch (*p) {
Expand Down
4 changes: 2 additions & 2 deletions test/regress/predef1.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ begin
report to_string(r, 0);
assert to_string(r, 0)(1 to 7) = "1.23456";

report to_string(r, "1.1f");
assert to_string(r, "1.1f") = "1.2";
report to_string(r, "%1.1f");
assert to_string(r, "%1.1f") = "1.2";

wait;
end process;
Expand Down

0 comments on commit 5d29bec

Please sign in to comment.