diff mbox series

[rt-tests,v2,3/3] cyclicdeadline: Fix buffer allocation

Message ID 20210708151827.21430-4-dwagner@suse.de
State New
Headers show
Series Fix a few fallouts | expand

Commit Message

Daniel Wagner July 8, 2021, 3:18 p.m. UTC
gcc complains with "‘sprintf’ output between 2 and 12 bytes" but
the buffer is only 10 bytes long. Update the buffer size to hold
the complete range of [-2147483648, 2147483646].

Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 src/sched_deadline/cyclicdeadline.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

John Kacur July 9, 2021, 6:01 p.m. UTC | #1
On Thu, 8 Jul 2021, Daniel Wagner wrote:

> gcc complains with "‘sprintf’ output between 2 and 12 bytes" but

> the buffer is only 10 bytes long. Update the buffer size to hold

> the complete range of [-2147483648, 2147483646].

> 

> Signed-off-by: Daniel Wagner <dwagner@suse.de>

> ---

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

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

> 

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

> index ffefa9e6fecb..8447424273ee 100644

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

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

> @@ -1092,7 +1092,7 @@ int main(int argc, char **argv)

>  

>  	/* Default cpu to use is the last one */

>  	if (!all_cpus && !setcpu) {

> -		setcpu_buf = malloc(10);

> +		setcpu_buf = malloc(12);

>  		if (!setcpu_buf)

>  			fatal("malloc");

>  		sprintf(setcpu_buf, "%d", cpu_count - 1);

> -- 

> 2.32.0

> 

> 

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


I applied this but there are others.

git grep PRIu64
src/oslat/oslat.c:              snprintf(bucket_name, sizeof(bucket_name), 
"%03"PRIu64
src/oslat/oslat.c:              putfield(bucket_name, t[i].buckets[j], 
PRIu64,
src/oslat/oslat.c:      putfield("Minimum", t[i].minlat, PRIu64, " (us)");
src/oslat/oslat.c:      putfield("Maximum", t[i].maxlat, PRIu64, " (us)");
src/oslat/oslat.c:      putfield("Max-Min", t[i].maxlat - t[i].minlat, 
PRIu64, " (us)");
src/oslat/oslat.c:              fprintf(f, "      \"min\": %" PRIu64 
",\n", t[i].minlat);
src/oslat/oslat.c:              fprintf(f, "      \"max\": %" PRIu64 
",\n", t[i].maxlat);
src/oslat/oslat.c:                      fprintf(f, "        \"%" PRIu64 
"\": %" PRIu64,
src/oslat/oslat.c:      printf("Workload mem: \t\t%"PRIu64" (KiB)\n",
src/pi_tests/pi_stress.c:               printf(" runtime %" PRIu64 " 
deadline %" PRIu64 " period %" PRIu64 "\n",
John Kacur July 9, 2021, 6:02 p.m. UTC | #2
On Thu, 8 Jul 2021, Daniel Wagner wrote:

> gcc complains with "‘sprintf’ output between 2 and 12 bytes" but

> the buffer is only 10 bytes long. Update the buffer size to hold

> the complete range of [-2147483648, 2147483646].

> 

> Signed-off-by: Daniel Wagner <dwagner@suse.de>

> ---

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

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

> 

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

> index ffefa9e6fecb..8447424273ee 100644

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

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

> @@ -1092,7 +1092,7 @@ int main(int argc, char **argv)

>  

>  	/* Default cpu to use is the last one */

>  	if (!all_cpus && !setcpu) {

> -		setcpu_buf = malloc(10);

> +		setcpu_buf = malloc(12);

>  		if (!setcpu_buf)

>  			fatal("malloc");

>  		sprintf(setcpu_buf, "%d", cpu_count - 1);

> -- 

> 2.32.0

> 

> 

Signed-off-by: John Kacur <jkacur@redhat.com>
Daniel Wagner July 19, 2021, 8:05 a.m. UTC | #3
On Fri, Jul 09, 2021 at 02:01:35PM -0400, John Kacur wrote:
> I applied this but there are others.


All those variables are defined as uint64_t, hence the PRIu64 is
correct.
diff mbox series

Patch

diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
index ffefa9e6fecb..8447424273ee 100644
--- a/src/sched_deadline/cyclicdeadline.c
+++ b/src/sched_deadline/cyclicdeadline.c
@@ -1092,7 +1092,7 @@  int main(int argc, char **argv)
 
 	/* Default cpu to use is the last one */
 	if (!all_cpus && !setcpu) {
-		setcpu_buf = malloc(10);
+		setcpu_buf = malloc(12);
 		if (!setcpu_buf)
 			fatal("malloc");
 		sprintf(setcpu_buf, "%d", cpu_count - 1);