RFR: 8256256: UL should not use heap allocation for output string [v2]

David Holmes david.holmes at oracle.com
Tue Dec 1 06:12:33 UTC 2020


On 1/12/2020 3:34 pm, Yumin Qi wrote:
> On Tue, 1 Dec 2020 04:43:58 GMT, David Holmes <dholmes at openjdk.org> wrote:
> 
>>> src/hotspot/share/logging/logTagSet.cpp line 129:
>>>
>>>> 127:   if ((size_t)ret >= sizeof(buf)) {
>>>> 128:     size_t newbuf_len = prefix_len + ret + 1;
>>>> 129:     char* newbuf = (char*)::calloc(newbuf_len, sizeof(char));
>>>
>>> Do we need to zero the array with calloc?
>>> The `(char*)` cast shouldn't be needed.
>>
>> The calloc query has not been addressed.
> 
> malloc/calloc return void* so need this cast.

That wasn't the query I meant - I meant why calloc not malloc? Why do we 
need to zero this memory? Is that just to avoid needing to figure out if 
we have to NUL terminate ourselves somewhere?

On the cast, in C you would not need it, but in C++ you do. I still tend 
to recall C rules. <sigh>

Thanks,
David
-----

> -------------
> 
> PR: https://git.openjdk.java.net/jdk/pull/1246
> 


More information about the hotspot-runtime-dev mailing list