diff mbox series

Fix snprintf format warnings during 'alsa' kselftest compilation

Message ID 20230223143214.16564-1-ivan.orlov0322@gmail.com (mailing list archive)
State New
Headers show
Series Fix snprintf format warnings during 'alsa' kselftest compilation | expand

Commit Message

Ivan Orlov Feb. 23, 2023, 2:32 p.m. UTC
Fix 'alsa' kselftest compilation warnings by making snprintf
format correspond the actual parameters types.

Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
---
 tools/testing/selftests/alsa/pcm-test.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Mark Brown Feb. 23, 2023, 3:05 p.m. UTC | #1
On Thu, Feb 23, 2023 at 05:32:14PM +0300, Ivan Orlov wrote:
> Fix 'alsa' kselftest compilation warnings by making snprintf
> format correspond the actual parameters types.

What warnings are you seeing in what configuration (arch, toolchain, any
custom options...)?  I'm not seeing anything when I test.  Are these
perhaps architecture dependent warnings?

Please submit patches using subject lines reflecting the style for the
subsystem, this makes it easier for people to identify relevant patches.
Look at what existing commits in the area you're changing are doing and
make sure your subject lines visually resemble what they're doing.
There's no need to resubmit to fix this alone.
Ivan Orlov Feb. 23, 2023, 8:14 p.m. UTC | #2
On 23.02.2023 18:05, Mark Brown wrote:

> What warnings are you seeing in what configuration (arch, toolchain, any
> custom options...)?  I'm not seeing anything when I test.  Are these
> perhaps architecture dependent warnings?
> 
> Please submit patches using subject lines reflecting the style for the
> subsystem, this makes it easier for people to identify relevant patches.
> Look at what existing commits in the area you're changing are doing and
> make sure your subject lines visually resemble what they're doing.
> There's no need to resubmit to fix this alone.

Thank you for the review! I will follow the common subject lines style 
in the future.

I compiled the test via gcc 11.3.0 without any custom options, the arch 
is x86_64. There were five warnings during the test compilation, and all 
of them were caused by incorrect format in 'snprintf' function calls. As 
I know, using incorrect format in 'snprintf' creates an undefined 
behavior. Maybe there is a point to fix it?
Mark Brown Feb. 27, 2023, 2:12 p.m. UTC | #3
On Thu, Feb 23, 2023 at 11:14:56PM +0300, Ivan Orlov wrote:

> I compiled the test via gcc 11.3.0 without any custom options, the arch is
> x86_64. There were five warnings during the test compilation, and all of
> them were caused by incorrect format in 'snprintf' function calls. As I
> know, using incorrect format in 'snprintf' creates an undefined behavior.
> Maybe there is a point to fix it?

The question is more where does the warning come from and is this a good
fix - a common pattern where generic types like size_t get used is that
the underlying type changes between platforms and warnings just get
moved about by changing the printf format around.
diff mbox series

Patch

diff --git a/tools/testing/selftests/alsa/pcm-test.c b/tools/testing/selftests/alsa/pcm-test.c
index f293c7d81009..52b109a162c6 100644
--- a/tools/testing/selftests/alsa/pcm-test.c
+++ b/tools/testing/selftests/alsa/pcm-test.c
@@ -318,7 +318,7 @@  static void test_pcm_time1(struct pcm_data *data,
 		goto __close;
 	}
 	if (rchannels != channels) {
-		snprintf(msg, sizeof(msg), "channels unsupported %ld != %ld", channels, rchannels);
+		snprintf(msg, sizeof(msg), "channels unsupported %ld != %u", channels, rchannels);
 		skip = true;
 		goto __close;
 	}
@@ -329,7 +329,7 @@  static void test_pcm_time1(struct pcm_data *data,
 		goto __close;
 	}
 	if (rrate != rate) {
-		snprintf(msg, sizeof(msg), "rate unsupported %ld != %ld", rate, rrate);
+		snprintf(msg, sizeof(msg), "rate unsupported %ld != %u", rate, rrate);
 		skip = true;
 		goto __close;
 	}
@@ -393,24 +393,24 @@  static void test_pcm_time1(struct pcm_data *data,
 			frames = snd_pcm_writei(handle, samples, rate);
 			if (frames < 0) {
 				snprintf(msg, sizeof(msg),
-					 "Write failed: expected %d, wrote %li", rate, frames);
+					 "Write failed: expected %ld, wrote %li", rate, frames);
 				goto __close;
 			}
 			if (frames < rate) {
 				snprintf(msg, sizeof(msg),
-					 "expected %d, wrote %li", rate, frames);
+					 "expected %ld, wrote %li", rate, frames);
 				goto __close;
 			}
 		} else {
 			frames = snd_pcm_readi(handle, samples, rate);
 			if (frames < 0) {
 				snprintf(msg, sizeof(msg),
-					 "expected %d, wrote %li", rate, frames);
+					 "expected %ld, wrote %li", rate, frames);
 				goto __close;
 			}
 			if (frames < rate) {
 				snprintf(msg, sizeof(msg),
-					 "expected %d, wrote %li", rate, frames);
+					 "expected %ld, wrote %li", rate, frames);
 				goto __close;
 			}
 		}