diff mbox series

[rt-tests,v1,v1,4/4] deadline_test: Increase buffer to avoid overflow

Message ID 20190819064304.4676-5-wagi@monom.org
State New
Headers show
Series Fix gcc warning | expand

Commit Message

Daniel Wagner Aug. 19, 2019, 6:43 a.m. UTC
Increase 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);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Daniel Wagner <wagi@monom.org>

---
 src/sched_deadline/deadline_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.21.0

Comments

John Kacur Aug. 23, 2019, 3:20 p.m. UTC | #1
On Mon, 19 Aug 2019, Daniel Wagner wrote:

> Increase 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);

>       |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> 

> Signed-off-by: Daniel Wagner <wagi@monom.org>

> ---

>  src/sched_deadline/deadline_test.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/src/sched_deadline/deadline_test.c b/src/sched_deadline/deadline_test.c

> index e2898de328bb..5b5f40dbb74d 100644

> --- a/src/sched_deadline/deadline_test.c

> +++ b/src/sched_deadline/deadline_test.c

> @@ -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);

> -- 

> 2.21.0

> 

Signed-off-by: John Kacur <jkacur@redhat.com>
diff mbox series

Patch

diff --git a/src/sched_deadline/deadline_test.c b/src/sched_deadline/deadline_test.c
index e2898de328bb..5b5f40dbb74d 100644
--- a/src/sched_deadline/deadline_test.c
+++ b/src/sched_deadline/deadline_test.c
@@ -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);