RFR: 8325002: Exceptions::fthrow needs to ensure it truncates to a valid utf8 string

David Holmes dholmes at openjdk.org
Sat Jul 27 12:22:30 UTC 2024


On Fri, 26 Jul 2024 21:35:08 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> src/hotspot/share/utilities/exceptions.cpp line 276:
>> 
>>> 274:   // sequence is valid.
>>> 275:   if ((ret == -1 || ret >= max_msg_size) && strlen(msg) > 0) {
>>> 276:     assert(msg[max_msg_size - 1] == '\0', "should be null terminated");
>> 
>> Would this always be true? For a formatting error, too?
>> Maybe just to be sure, instead of asserting set the last byte to zero.
>
> vsnprintf is supposed to guarantee it, and os::vsnprint does IIRC, so this is just a sanity check.

Yep os::vnsprintf guarantees nul-termination

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20345#discussion_r1693949707


More information about the hotspot-dev mailing list