On Tue, 25 Jul 2023 21:00:17 GMT, Sergey Bylokhov <s...@openjdk.org> wrote:
>> @dholmes-ora could I trouble you for a sponsor? Thanks! > > @TheShermanTanker Working on a similar cleanup, and wonder if is it correct > to assume that the "snprintf" adds "nul" even in case of error. > For example, this code was removed by this patch: > > > if (rc < 0) { > /* apply ansi semantics */ > buffer[size - 1] = '\0'; > return (int)size; > } else if (rc == size) { > /* force a null terminator */ > buffer[size - 1] = '\0'; > } > > > If the result of "snprintf" was negative we always set the '\0'. But what > about default "snprintf"? @mrserb snprintf in the UCRT does indeed null terminate the buffer, conforming to C99. The relevant behaviour can be found documented under https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/snprintf-snprintf-snprintf-l-snwprintf-snwprintf-l?view=msvc-170#behavior-summary ------------- PR Comment: https://git.openjdk.org/jdk/pull/10625#issuecomment-1650700451