On Sat, 13 Jul 2024 05:34:24 GMT, Julian Waters <jwat...@openjdk.org> wrote:

>> snprintf has been available for all officially and unofficially supported 
>> compilers for Windows, Visual Studio since version 2015 and gcc since, well, 
>> forever. snprintf is conforming to C99 since the start when compiling using 
>> gcc, and 2015 when using Visual Studio. Since it conforms to C99 and 
>> provides better semantics than _snprintf, and is not compiler specific, we 
>> should use it in most places where we currently use _snprintf. This makes 
>> JDK code where this is used more robust due to the null terminating 
>> guarantee of snprintf. Since most of the changes are extremely simple, I've 
>> included all of them hoping to get this all done in one shot. The only 
>> places _snprintf is not replaced is places where I'm not sure whether the 
>> code is ours or not (As in, imported source code for external libraries). 
>> Note that the existing checks in place for the size of the characters 
>> written still work, as the return value of snprintf works mostly the same as 
>> _snprintf. The only difference is the nu
 ll terminating character at the end and the returning of the number of written 
characters if the buffer was terminated early, as seen here: 
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/snprintf-snprintf-snprintf-l-snwprintf-snwprintf-l?view=msvc-170
>> 
>> Reviews Required: 2 for HotSpot, jdk.hotspot.agent, and jdk.jdwp.agent, 1 
>> for awt and jdk.accessibility, 1 for java.base, 1 for security, 1 for 
>> jdk.management(?)
>
> Julian Waters has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   USe os::snprintf in HotSpot

Changes requested by kbarrett (Reviewer).

src/jdk.jdwp.agent/windows/native/libjdwp/util_md.h line 32:

> 30: #include <stdlib.h>      /* for _MAx_PATH */
> 31: 
> 32: typedef unsigned long long UNSIGNED_JLONG;

This change has nothing to do with _sprintf.  Not sure why it's being made here.

src/jdk.management/windows/native/libmanagement_ext/OperatingSystemImpl.c line 
54:

> 52: 
> 53: typedef unsigned int juint;
> 54: typedef unsigned long long julong;

Similarly, his change has nothing to do with _sprintf.

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

PR Review: https://git.openjdk.org/jdk/pull/20153#pullrequestreview-2178184310
PR Review Comment: https://git.openjdk.org/jdk/pull/20153#discussion_r1678105753
PR Review Comment: https://git.openjdk.org/jdk/pull/20153#discussion_r1678106243

Reply via email to