testsuite/smokey/sched-quota: Allow building with gcc 12
PATCH 1/1 testsuite/smokey/sched-quota: Allow building with gcc 12
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.
---
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(-)
testsuite/smokey/sched-quota/sched-quota.c +2 -2
@@ -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); }
Signature · 1 line
2.39.1