All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] testsuite/smokey/sched-quota: Allow building with gcc 12
@ 2023-02-15 14:04 Florian Bezdeka
  0 siblings, 0 replies; only message in thread
From: Florian Bezdeka @ 2023-02-15 14:04 UTC (permalink / raw)
  To: xenomai; +Cc: jan.kiszka, Florian Bezdeka

The build wich gcc 12 failed with two overflow warnings. gcc is more strict
in checking specifier overflows now.

In this case %d alone would require up to 10 characters but only 8 where
available.

The warning:

sched-quota.c: In function ‘calibrate’:
sched-quota.c:244:34: error: ‘%d’ directive writing between 1 and 10 bytes into a region of size 7 [-Werror=format-overflow=]
  244 |                 sprintf(label, "t%d", n);
      |                                  ^~
sched-quota.c:244:32: note: directive argument in the range [0, 2147483646]
  244 |                 sprintf(label, "t%d", n);
      |                                ^~~~~
sched-quota.c:244:17: note: ‘sprintf’ output between 3 and 12 bytes into a destination of size 8
  244 |                 sprintf(label, "t%d", n);

Fixed by migrating to snprintf and adding a limit to the actual buffer
size.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---

Hi all,

this patch can be applied to the following (stable) branches:
 - next
 - stable/v3.0.x
 - stable/v3.1.x
 - stable/v3.2.x

It allows to use gcc 12 (coming with Debian 12) as compiler for the
Xenomai code base.

Best regards,
Florian

 testsuite/smokey/sched-quota/sched-quota.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/testsuite/smokey/sched-quota/sched-quota.c b/testsuite/smokey/sched-quota/sched-quota.c
index acb9055fd..093f7db43 100644
--- a/testsuite/smokey/sched-quota/sched-quota.c
+++ b/testsuite/smokey/sched-quota/sched-quota.c
@@ -184,7 +184,7 @@ static double run_quota(int quota)
 		     tgid, cf.quota.info.quota_sum);
 
 	for (n = 0; n < nrthreads; n++) {
-		sprintf(label, "t%d", n);
+		snprintf(label, sizeof(label), "t%d", n);
 		create_quota_thread(threads[n], label, tgid, counts[n]);
 		sem_wait(&ready);
 	}
@@ -241,7 +241,7 @@ static unsigned long long calibrate(void)
 	crunch_per_sec = (unsigned long long)((double)ONE_BILLION / (double)ns * crunch_loops);
 
 	for (n = 0; n < nrthreads; n++) {
-		sprintf(label, "t%d", n);
+		snprintf(label, sizeof(label), "t%d", n);
 		create_fifo_thread(threads[n], label, counts[n]);
 		sem_wait(&ready);
 	}
-- 
2.39.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-15 14:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-15 14:04 [PATCH] testsuite/smokey/sched-quota: Allow building with gcc 12 Florian Bezdeka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.