Fix gcc warning
cover Fix gcc warning
On F29 and F30 gcc is warning about too small buffers. Let's fix this.
Daniel Wagner (4):
pmqtest: Increase buffer to avoid overflow
sigwaittest: Increase buffer to avoid overflow
svsematest: Increase buffer to avoid overflow
deadline_test: Increase buffer to avoid overflow
src/pmqtest/pmqtest.c | 4 ++-- src/sched_deadline/deadline_test.c | 2 +- src/sigwaittest/sigwaittest.c | 2 +- src/svsematest/svsematest.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.21.0
PATCH 1/4 pmqtest: Increase buffer to avoid overflow
Increase the size of the char buffer. gcc 9.1.1 reports:
src/pmqtest/pmqtest.c: In function ‘main’:src/pmqtest/pmqtest.c:46:21: warning: ‘%d’ directive writing between 1 and 10 bytes into a region of size 8 [-Wformat-overflow=]
46 | #define SYNCMQ_NAME "/syncmsg%d"
| ^~~~~~~~~~~~
src/pmqtest/pmqtest.c:445:3: note: ‘sprintf’ output between 10 and 19 bytes into a destination of size 16
445 | sprintf(mqname, SYNCMQ_NAME, i);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--- src/pmqtest/pmqtest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/pmqtest/pmqtest.c +2 -2
@@ -440,7 +440,7 @@ int main(int argc, char *argv[]) goto nomem;for (i =0 ; i < num_threads; i++) { -char mqname[16 ]; +char mqname[32 ];sprintf (mqname,SYNCMQ_NAME , i); receiver[i].syncmq =mq_open (mqname, oflag,0777 , &mqstat);
@@ -567,7 +567,7 @@ int main(int argc, char *argv[]) }nanosleep (&maindelay,NULL );for (i =0 ; i < num_threads; i++) { -char mqname[16 ]; +char mqname[32 ];mq_close (receiver[i].syncmq);sprintf (mqname,SYNCMQ_NAME , i);
Signature · 1 line
2.21.0
Re: [PATCH rt-tests v0 1/4] pmqtest: Increase buffer to avoid overflow
Quoted 21 lines · Daniel Wagner
Increase the size of the char buffer. gcc 9.1.1 reports:
src/pmqtest/pmqtest.c: In function ‘main’:src/pmqtest/pmqtest.c:46:21: warning: ‘%d’ directive writing between 1 and 10 bytes into a region of size 8 [-Wformat-overflow=]
46 | #defineSYNCMQ_NAME"/syncmsg%d"| ^~~~~~~~~~~~
src/pmqtest/pmqtest.c:445:3: note: ‘sprintf’ output between 10 and 19 bytes into a destination of size 16445 | sprintf(mqname, SYNCMQ_NAME, i); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Signed-off-by Daniel Wagner <[email protected]>--- src/pmqtest/pmqtest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)src/pmqtest/pmqtest.c +0
-0
src/pmqtest/pmqtest.c int main(int argc, char *argv[]) · line 443
Quoted 5 lines
src/pmqtest/pmqtest.c +1
-1@@ -440,7 +440,7 @@ int main(int argc, char *argv[]) goto nomem;for (i =0 ; i < num_threads; i++) { -char mqname[16 ]; +char mqname[32 ];
The compiler says, based on SYNCMQ_NAME's size and maximum possible %d we will have 19 bytes max. Why do you change it to 32? Why it is not wrong, one might ask what the extra storage is for.
Sebastian
Re: [PATCH rt-tests v0 1/4] pmqtest: Increase buffer to avoid overflow
Quoted 24 lines · Sebastian Andrzej Siewior
Quoted 23 lines · Daniel Wagner
Increase the size of the char buffer. gcc 9.1.1 reports:
src/pmqtest/pmqtest.c: In function ‘main’:src/pmqtest/pmqtest.c:46:21: warning: ‘%d’ directive writing between 1 and 10 bytes into a region of size 8 [-Wformat-overflow=]
46 | #defineSYNCMQ_NAME"/syncmsg%d"
| ^~~~~~~~~~~~
src/pmqtest/pmqtest.c:445:3: note: ‘sprintf’ output between 10 and 19 bytes into a destination of size 16445 | sprintf(mqname, SYNCMQ_NAME, i); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Signed-off-by Daniel Wagner <[email protected]>--- src/pmqtest/pmqtest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)src/pmqtest/pmqtest.c +0
-0@@ -440,7 +440,7 @@ int main(int argc, char *argv[]) goto nomem;
Quoted 7 lines
src/pmqtest/pmqtest.c int main(int argc, char *argv[]) · line 443
Quoted 3 lines
src/pmqtest/pmqtest.c +1
-1for (i =0 ; i < num_threads; i++) { -char mqname[16 ]; +char mqname[32 ];The compiler says, based on SYNCMQ_NAME's size and maximum possible %d we will have 19 bytes max. Why do you change it to 32? Why it is not wrong, one might ask what the extra storage is for.
I was taking the 16 bytes value as reference and doubled it. Indeed, 19 bytes would be a better choice. Let me refresh the series.
PATCH 2/4 sigwaittest: Increase buffer to avoid overflow
In reply to Daniel WagnerIncrease the size of the char buffer. gcc 9.1.1 reports:
src/sigwaittest/sigwaittest.c:494:5: note: ‘sprintf’ output between 5 and 14 bytes into a destination of size 8
494 | sprintf(f_opt, "-fr%d", i);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~src/sigwaittest/sigwaittest.c:522:24: warning: ‘%d’ directive writing between 1 and 10 bytes into a region of size 5 [-Wformat-overflow=]
522 | sprintf(f_opt, "-fs%d", i);
| ^~
--- src/sigwaittest/sigwaittest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/sigwaittest/sigwaittest.c +1 -1
@@ -352,7 +352,7 @@ int main(int argc, char *argv[])struct params *sender =NULL ;sigset_t sigset;void *param =NULL ; -char f_opt[8 ]; +char f_opt[32 ];struct timespec launchdelay, maindelay;process_options (argc, argv);
Signature · 1 line
2.21.0
PATCH 3/4 svsematest: Increase buffer to avoid overflow
In reply to Daniel WagnerIncrease the size of the char buffer. gcc 9.1.1 reports:
rc/svsematest/svsematest.c:578:24: warning: ‘%d’ directive writing between 1 and 10 bytes into a region of size 5 [-Wformat-overflow=]
578 | sprintf(f_opt, "-fr%d", i);
| ^~src/svsematest/svsematest.c:606:5: note: ‘sprintf’ output between 5 and 14 bytes into a destination of size 8
606 | sprintf(f_opt, "-fs%d", i);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~--- src/svsematest/svsematest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/svsematest/svsematest.c +1 -1
@@ -401,7 +401,7 @@ int main(int argc, char *argv[])struct params *sender =NULL ;sigset_t sigset;void *param =NULL ; -char f_opt[8 ]; +char f_opt[32 ];struct timespec launchdelay, maindelay; myfile =getenv ("_" );
Signature · 1 line
2.21.0
PATCH 4/4 deadline_test: Increase buffer to avoid overflow
In reply to Daniel WagnerIncrease the size of the char buffer. gcc 9.1.1 reports:
src/sched_deadline/deadline_test.c:1803:24: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 10 [-Wformat-overflow=]
1803 | sprintf(setcpu_buf, "%d", cpu_count - 1);
| ^~src/sched_deadline/deadline_test.c:1803:23: note: directive argument in the range [-2147483648, 2147483646]
1803 | sprintf(setcpu_buf, "%d", cpu_count - 1);
| ^~~~src/sched_deadline/deadline_test.c:1803:3: note: ‘sprintf’ output between 2 and 12 bytes into a destination of size 10
1803 | sprintf(setcpu_buf, "%d", cpu_count - 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--- src/sched_deadline/deadline_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/sched_deadline/deadline_test.c +1 -1
@@ -1795,7 +1795,7 @@ int main (int argc, char **argv)/* -b has us bind to the last CPU. */ if (!all_cpus && !setcpu) { - setcpu_buf =malloc (10 ); + setcpu_buf =malloc (12 );if (!setcpu_buf) {perror ("malloc" );exit (-1 );
Signature · 1 line
2.21.0