public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix snprintf format warnings during 'alsa' kselftest compilation
@ 2023-02-23 14:32 Ivan Orlov
  2023-02-23 15:05 ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Ivan Orlov @ 2023-02-23 14:32 UTC (permalink / raw)
  To: broonie, perex, tiwai, shuah
  Cc: Ivan Orlov, alsa-devel, linux-kselftest, linux-kernel, skhan

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(-)

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;
 			}
 		}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix snprintf format warnings during 'alsa' kselftest compilation
  2023-02-23 14:32 [PATCH] Fix snprintf format warnings during 'alsa' kselftest compilation Ivan Orlov
@ 2023-02-23 15:05 ` Mark Brown
  2023-02-23 20:14   ` Ivan Orlov
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2023-02-23 15:05 UTC (permalink / raw)
  To: Ivan Orlov
  Cc: perex, tiwai, shuah, alsa-devel, linux-kselftest, linux-kernel,
	skhan

[-- Attachment #1: Type: text/plain, Size: 687 bytes --]

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.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix snprintf format warnings during 'alsa' kselftest compilation
  2023-02-23 15:05 ` Mark Brown
@ 2023-02-23 20:14   ` Ivan Orlov
  2023-02-27 14:12     ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Ivan Orlov @ 2023-02-23 20:14 UTC (permalink / raw)
  To: Mark Brown
  Cc: perex, tiwai, shuah, alsa-devel, linux-kselftest, linux-kernel,
	skhan

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?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix snprintf format warnings during 'alsa' kselftest compilation
  2023-02-23 20:14   ` Ivan Orlov
@ 2023-02-27 14:12     ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2023-02-27 14:12 UTC (permalink / raw)
  To: Ivan Orlov
  Cc: perex, tiwai, shuah, alsa-devel, linux-kselftest, linux-kernel,
	skhan

[-- Attachment #1: Type: text/plain, Size: 663 bytes --]

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.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-27 14:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-23 14:32 [PATCH] Fix snprintf format warnings during 'alsa' kselftest compilation Ivan Orlov
2023-02-23 15:05 ` Mark Brown
2023-02-23 20:14   ` Ivan Orlov
2023-02-27 14:12     ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox