On Wed, 29 Nov 2023 20:31:50 GMT, Chris Plummer <cjplum...@openjdk.org> wrote:

>> src/hotspot/share/services/heapDumper.cpp line 2026:
>> 
>>> 2024:     size_t buf_size = strlen(base_path)
>>> 2025:                     + 2                 // ".p"
>>> 2026:                     + 1 + (seq / 10)    // number
>> 
>> Is this suppose to be the number of characters the sequence number will take 
>> up in the path? If so, that's not the correct calculation. For example, 35 
>> ends up as 1 + 3 == 4, but it should be 2.
>
> I think the easiest solution is probably just coming up with some reasonable 
> max sequence number and then just assuming that you will need enough chars 
> for it. But if you want to actually compute it, there are a few solutions, 
> including a simple div by 10 loop.

`sprintf` can be simple to use:

 char result[100]; 
 int number_of_digits = sprintf(result, "%d", seq);

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16665#discussion_r1409930475

Reply via email to