RFR: 8347576: Error output in libjsound has non matching format strings [v4]

Julian Waters jwaters at openjdk.org
Wed Jan 15 14:22:45 UTC 2025


On Wed, 15 Jan 2025 14:12:11 GMT, Matthias Baesken <mbaesken at openjdk.org> wrote:

>> src/java.desktop/share/native/libjsound/MidiOutDevice.c line 97:
>> 
>>> 95:     /* Handle error codes. */
>>> 96:     if (ret < -1) {
>>> 97:         ERROR1("Java_com_sun_media_sound_MidiOutDevice_nGetTimeStamp: MIDI_IN_GetTimeStamp returned %lld\n", (long long int) ret);
>> 
>> I wonder if we could use the format specifier for jlong here somehow, avoiding the cast here
>
> I think we do not have this now in this lib. Of course we can copy something like this
> 
> test/hotspot/jtreg/vmTestbase/nsk/share/native/nsk_tools.hpp 
> 
> 30  #include <inttypes.h>
> 
> 34  #if defined(_LP64) && defined(__APPLE__)
> 35  #define JLONG_FORMAT "%ld"
> 36  #else  // _LP64 && __APPLE__
> 37  #define JLONG_FORMAT "%" PRId64
> 38  #endif // _LP64 && __APPLE__
> 
> 
> into the file and then use JLONG_FORMAT .
> Is this worth it?

That seems preferable, but I'll leave it up to you and the other people who reviewed this on where to put the define, whether locally in the file, or in a header

>> src/java.desktop/windows/native/libjsound/PLATFORM_API_WinOS_MidiIn.cpp line 60:
>> 
>>> 58:     MidiDeviceHandle* handle = (MidiDeviceHandle*) dwInstance;
>>> 59: 
>>> 60:     TRACE3("> MIDI_IN_PutMessage, hMidiIn: 0x%" PRIxPTR ", wMsg: %x, dwInstance: 0x%" PRIxPTR "\n", (uintptr_t)hMidiIn, wMsg, (uintptr_t)dwInstance);
>> 
>> It's surprisingly difficult to find the type of HMIDIIN, but the rest of the types here are UINT_PTR and hence %x seems correct
>
> Here the compile error we get ; %x does not work for HMIDIIN or UINT_PTR.
> 
> 
> c:\builddir\jdk\src\java.desktop\windows\native\libjsound\PLATFORM_API_WinOS_MidiIn.cpp(58): error C2220: the following warning is treated as an error
> c:\builddir\jdk\src\java.desktop\windows\native\libjsound\PLATFORM_API_WinOS_MidiIn.cpp(58): warning C4477: 'fprintf' : format string '%x' requires an argument of type 'unsigned int', but variadic argument 1 has type 'HMIDIIN'
> c:\builddir\jdk\src\java.desktop\windows\native\libjsound\PLATFORM_API_WinOS_MidiIn.cpp(58): warning C4313: 'fprintf': '%x' in format string conflicts with argument 1 of type 'HMIDIIN'
> c:\builddir\jdk\src\java.desktop\windows\native\libjsound\PLATFORM_API_WinOS_MidiIn.cpp(58): warning C4477: 'fprintf' : format string '%x' requires an argument of type 'unsigned int', but variadic argument 3 has type 'UINT_PTR'
> c:\builddir\jdk\src\java.desktop\windows\native\libjsound\PLATFORM_API_WinOS_MidiIn.cpp(58): note: consider using '%llx' in the format string
> c:\builddir\jdk\src\java.desktop\windows\native\libjsound\PLATFORM_API_WinOS_MidiIn.cpp(58): note: consider using '%Ix' in the format string
> c:\builddir\jdk\src\java.desktop\windows\native\libjsound\PLATFORM_API_WinOS_MidiIn.cpp(58): note: consider using '%I64x' in the format string
> c:\builddir\jdk\src\java.desktop\windows\native\libjsound\PLATFORM_API_WinOS_MidiIn.cpp(59): warning C4477: 'fprintf' : format string '%x' requires an argument of type 'unsigned int', but variadic argument 1 has type 'UINT_PTR'
> c:\builddir\jdk\src\java.desktop\windows\native\libjsound\PLATFORM_API_WinOS_MidiIn.cpp(59): note: consider using '%llx' in the format string
> c:\builddir\jdk\src\java.desktop\windows\native\libjsound\PLATFORM_API_WinOS_MidiIn.cpp(59): note: consider using '%Ix' in the format string
> c:\builddir\jdk\src\java.desktop\windows\native\libjsound\PLATFORM_API_WinOS_MidiIn.cpp(59): note: consider using '%I64x' in the format string
> c:\builddir\jdk\src\java.desktop\windows\native\libjsound\PLATFORM_API_WinOS_MidiIn.cpp(59): warning C4477: 'fprintf' : format string '%x' requires an argument of type 'unsigned int', but variadic argument 2 has type 'UINT_PTR'
> c:\builddir\jdk\src\java.desktop\windows\native\libjsound\PLATFORM_API_WinOS_MidiIn.cpp(59): note: consider using '%llx' in the format string
> c:\builddir\jdk\src\java.desktop\windows\native\libjsound\PLATFORM_API_WinOS_MidiIn.cpp(59): note: consider using '%Ix' in the format string
>    ... (rest of output omitted)

Ah, I just checked, UINT_PTR confusingly differs depending on certain defines. Alright, makes sense, though I still haven't figured out what type HMIDIIN is

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23076#discussion_r1916727458
PR Review Comment: https://git.openjdk.org/jdk/pull/23076#discussion_r1916730912


More information about the client-libs-dev mailing list