Skip to contentSkip to conversation

testsuite/smokey/sched-quota: Allow building with gcc 12

PATCH Applied Florian Bezdeka 2 participants 2 messages Feb 15, 2023 – Feb 16, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 testsuite/smokey/sched-quota: Allow building with gcc 12

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

In this case "t%d" requires up to 12 characters but only 8 were 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 extending the label/buffer space. In addition the migration to snprintf avoids a buffer overflow.

---

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

Changes since v1:
- Rephrase commit message
- Extend the buffer space (detected in the stable/v3.0.x branch)

 testsuite/smokey/sched-quota/sched-quota.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
testsuite/smokey/sched-quota/sched-quota.c +4 -4
index acb9055fd..26bc15e72 100644
@@ -163,7 +163,7 @@ static double run_quota(int quota)
 	struct timespec req;
 	int ret, tgid, n;
 	double percent;
-	char label[8];
+	char label[12];
 
 	cf.quota.op = sched_quota_add;
 	cf.quota.add.pshared = 0;
@@ -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);
 	}
@@ -228,7 +228,7 @@ static unsigned long long calibrate(void)
 	unsigned long long ns, lps;
 	unsigned long count;
 	struct timespec req;
-	char label[8];
+	char label[12];
 	int n;
 
 	count = 0;
@@ -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
Applied
#1 lore raw
Quoted 77 lines · Florian Bezdeka

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

In this case "t%d" requires up to 12 characters but only 8 were 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 extending the label/buffer space. In addition the migration to snprintf avoids a buffer overflow.

---

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

Changes since v1:
- Rephrase commit message
- Extend the buffer space (detected in the stable/v3.0.x branch)

 testsuite/smokey/sched-quota/sched-quota.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
testsuite/smokey/sched-quota/sched-quota.c +3 -3
index acb9055fd..26bc15e72 100644
@@ -163,7 +163,7 @@ static double run_quota(int quota)
 	struct timespec req;
 	int ret, tgid, n;
 	double percent;
-	char label[8];
+	char label[12];
 
 	cf.quota.op = sched_quota_add;
 	cf.quota.add.pshared = 0;
@@ -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);
 	}
@@ -228,7 +228,7 @@ static unsigned long long calibrate(void)
 	unsigned long long ns, lps;
 	unsigned long count;
 	struct timespec req;
-	char label[8];
+	char label[12];
 	int n;
 
 	count = 0;

testsuite/smokey/sched-quota/sched-quota.c static unsigned long long calibrate(void) · line 247

Quoted 8 lines
testsuite/smokey/sched-quota/sched-quota.c +1 -1
@@ -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);
 	}

Thanks, applied.

Jan

Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux