RFR: 8256828: ostream::print_cr() truncates buffer in copy-through case [v3]

Thomas Stuefe stuefe at openjdk.org
Tue Jun 4 05:19:18 UTC 2024


On Mon, 3 Jun 2024 07:14:19 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> src/hotspot/share/utilities/ostream.hpp line 74:
>> 
>>> 72:   // of the returned string.
>>> 73:   //
>>> 74:   // In a debug build, if truncation occurs a VM warning is issued.
>> 
>> I had to think a bit (I am not a native English speaker) about what the "Nominally" means, but I think it is supposed to contrast the second paragraph? As in "Normally we do that, but in the case of ... we do... ?". Same for "idiomatically" - what does that signify?
>
> Right "nominally" is indicating that it basically operates one way but there are exceptions as outlined in the second paragraph.
> 
> "idiomatically" means we are applying a specific coding idiom aka pattern - in this case secure programming says you never pass a non-constant string to a printf-like function, but instead pass "%s" and supply the actual string as the argument. So when we encounter that idiom we will handle it specially.

If you go for a clear behavior description, there are a few infos missing:
- result_len contains the length of the returned string, including trailing cr, excluding trailing nul
- function will always print the trailing cr regardless of truncation (e.g., print_cr("abc") with output buffer of 2 will just return a cr).

But I wonder whether we can shorten the description to something like this:

"Function will return a formatted string. It may bypass the caller-provided output buffer, returning the provided format string directly, if no formatting or copying is needed."

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19512#discussion_r1625327284


More information about the hotspot-dev mailing list