RFR: 8254270: linux 32 bit build doesn't compile libjdwp/log_messages.c
Claes Redestad
redestad at openjdk.java.net
Thu Nov 5 19:43:57 UTC 2020
On Thu, 5 Nov 2020 18:35:52 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
> ... so the problem would be that the compiler does not believe us that millisecs will be always <1000. And there is no way to truncate output for numerical format specifiers.
Interesting, and a reasonable explanation. Odd this doesn't get caught by the 64-bit build
>
> One solution could be to first print the millisecs to a buffer large enough to hold MAX_INT. And then print that buffer as a string, which can be truncated with precision.
>
> ```
> char tmp[10 + 1];
> snprintf(tmp, sizeof(tmp), "%d", millisecs);
> snprintf(tbuf, ltbuf, "%s.%.3s %s", timestamp_date_time, tmp, timestamp_timezone);
> ```
>
> That may be enough to shut the compiler up.
It'd be interesting to see if statically limiting the value printed to be < 1000 would also convince the compiler, e.g.
`snprintf(tbuf, ltbuf, "%s.%.3d %s", timestamp_date_time, millisecs % 1000, timestamp_timezone);`
(I'm not sure a perfect solution is worth our while here, but seeing we've gotten this far down the rabbit hole..)
-------------
PR: https://git.openjdk.java.net/jdk/pull/1067
More information about the serviceability-dev
mailing list