mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests/proc: Fix string literal warning in proc-maps-race.c
@ 2025-08-03 20:47 Sukrut Heroorkar
  2025-08-04 19:47 ` Suren Baghdasaryan
  0 siblings, 1 reply; 3+ messages in thread
From: Sukrut Heroorkar @ 2025-08-03 20:47 UTC (permalink / raw)
  To: Shuah Khan, Suren Baghdasaryan, Andrew Morton, Sukrut Heroorkar,
	open list:PROC FILESYSTEM, open list:PROC FILESYSTEM,
	open list:KERNEL SELFTEST FRAMEWORK
  Cc: skhar, david.hunter.linux

This change resolves non literal string format warning invoked
for proc-maps-race.c while compiling.

proc-maps-race.c:205:17: warning: format not a string literal and no format arguments [-Wformat-security]
  205 |                 printf(text);
      |                 ^~~~~~
proc-maps-race.c:209:17: warning: format not a string literal and no format arguments [-Wformat-security]
  209 |                 printf(text);
      |                 ^~~~~~
proc-maps-race.c: In function ‘print_last_lines’:
proc-maps-race.c:224:9: warning: format not a string literal and no format arguments [-Wformat-security]
  224 |         printf(start);
      |         ^~~~~~

Added string format specifier %s for the printf calls
in both print_first_lines() and print_last_lines() thus
resolving the warnings invoked.

The test executes fine after this change thus causing no
affect to the functional behavior of the test.

Signed-off-by: Sukrut Heroorkar <hsukrut3@gmail.com>
---
 tools/testing/selftests/proc/proc-maps-race.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/proc/proc-maps-race.c b/tools/testing/selftests/proc/proc-maps-race.c
index 66773685a047..94bba4553130 100644
--- a/tools/testing/selftests/proc/proc-maps-race.c
+++ b/tools/testing/selftests/proc/proc-maps-race.c
@@ -202,11 +202,11 @@ static void print_first_lines(char *text, int nr)
 		int offs = end - text;
 
 		text[offs] = '\0';
-		printf(text);
+		printf("%s", text);
 		text[offs] = '\n';
 		printf("\n");
 	} else {
-		printf(text);
+		printf("%s", text);
 	}
 }
 
@@ -221,7 +221,7 @@ static void print_last_lines(char *text, int nr)
 		nr--;
 		start--;
 	}
-	printf(start);
+	printf("%s", start);
 }
 
 static void print_boundaries(const char *title, FIXTURE_DATA(proc_maps_race) *self)
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/proc: Fix string literal warning in proc-maps-race.c
  2025-08-03 20:47 [PATCH] selftests/proc: Fix string literal warning in proc-maps-race.c Sukrut Heroorkar
@ 2025-08-04 19:47 ` Suren Baghdasaryan
  2025-08-04 21:48   ` sukrut heroorkar
  0 siblings, 1 reply; 3+ messages in thread
From: Suren Baghdasaryan @ 2025-08-04 19:47 UTC (permalink / raw)
  To: Sukrut Heroorkar
  Cc: Shuah Khan, Andrew Morton, open list:PROC FILESYSTEM,
	open list:PROC FILESYSTEM, open list:KERNEL SELFTEST FRAMEWORK,
	skhar, david.hunter.linux

On Sun, Aug 3, 2025 at 1:48 PM Sukrut Heroorkar <hsukrut3@gmail.com> wrote:
>
> This change resolves non literal string format warning invoked
> for proc-maps-race.c while compiling.
>
> proc-maps-race.c:205:17: warning: format not a string literal and no format arguments [-Wformat-security]
>   205 |                 printf(text);
>       |                 ^~~~~~
> proc-maps-race.c:209:17: warning: format not a string literal and no format arguments [-Wformat-security]
>   209 |                 printf(text);
>       |                 ^~~~~~
> proc-maps-race.c: In function ‘print_last_lines’:
> proc-maps-race.c:224:9: warning: format not a string literal and no format arguments [-Wformat-security]
>   224 |         printf(start);
>       |         ^~~~~~
>
> Added string format specifier %s for the printf calls
> in both print_first_lines() and print_last_lines() thus
> resolving the warnings invoked.
>
> The test executes fine after this change thus causing no
> affect to the functional behavior of the test.

Please add:

Fixes: aadc099c480f ("selftests/proc: add verbose mode for
/proc/pid/maps tearing tests")

>
> Signed-off-by: Sukrut Heroorkar <hsukrut3@gmail.com>

Acked-by: Suren Baghdasaryan <surenb@google.com>

Thanks,
Suren.

> ---
>  tools/testing/selftests/proc/proc-maps-race.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/proc/proc-maps-race.c b/tools/testing/selftests/proc/proc-maps-race.c
> index 66773685a047..94bba4553130 100644
> --- a/tools/testing/selftests/proc/proc-maps-race.c
> +++ b/tools/testing/selftests/proc/proc-maps-race.c
> @@ -202,11 +202,11 @@ static void print_first_lines(char *text, int nr)
>                 int offs = end - text;
>
>                 text[offs] = '\0';
> -               printf(text);
> +               printf("%s", text);
>                 text[offs] = '\n';
>                 printf("\n");
>         } else {
> -               printf(text);
> +               printf("%s", text);
>         }
>  }
>
> @@ -221,7 +221,7 @@ static void print_last_lines(char *text, int nr)
>                 nr--;
>                 start--;
>         }
> -       printf(start);
> +       printf("%s", start);
>  }
>
>  static void print_boundaries(const char *title, FIXTURE_DATA(proc_maps_race) *self)
> --
> 2.43.0
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/proc: Fix string literal warning in proc-maps-race.c
  2025-08-04 19:47 ` Suren Baghdasaryan
@ 2025-08-04 21:48   ` sukrut heroorkar
  0 siblings, 0 replies; 3+ messages in thread
From: sukrut heroorkar @ 2025-08-04 21:48 UTC (permalink / raw)
  To: Suren Baghdasaryan
  Cc: Shuah Khan, Andrew Morton, open list:PROC FILESYSTEM,
	open list:PROC FILESYSTEM, open list:KERNEL SELFTEST FRAMEWORK,
	skhar, david.hunter.linux

Hi Suren,

On Mon, Aug 4, 2025 at 9:47 PM Suren Baghdasaryan <surenb@google.com> wrote:
>
> On Sun, Aug 3, 2025 at 1:48 PM Sukrut Heroorkar <hsukrut3@gmail.com> wrote:
> >
> > This change resolves non literal string format warning invoked
> > for proc-maps-race.c while compiling.
> >
> > proc-maps-race.c:205:17: warning: format not a string literal and no format arguments [-Wformat-security]
> >   205 |                 printf(text);
> >       |                 ^~~~~~
> > proc-maps-race.c:209:17: warning: format not a string literal and no format arguments [-Wformat-security]
> >   209 |                 printf(text);
> >       |                 ^~~~~~
> > proc-maps-race.c: In function ‘print_last_lines’:
> > proc-maps-race.c:224:9: warning: format not a string literal and no format arguments [-Wformat-security]
> >   224 |         printf(start);
> >       |         ^~~~~~
> >
> > Added string format specifier %s for the printf calls
> > in both print_first_lines() and print_last_lines() thus
> > resolving the warnings invoked.
> >
> > The test executes fine after this change thus causing no
> > affect to the functional behavior of the test.
>
> Please add:
>
> Fixes: aadc099c480f ("selftests/proc: add verbose mode for
> /proc/pid/maps tearing tests")
>
> >
> > Signed-off-by: Sukrut Heroorkar <hsukrut3@gmail.com>
>
> Acked-by: Suren Baghdasaryan <surenb@google.com>
>
> Thanks,
> Suren.
>
> > ---
> >  tools/testing/selftests/proc/proc-maps-race.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/tools/testing/selftests/proc/proc-maps-race.c b/tools/testing/selftests/proc/proc-maps-race.c
> > index 66773685a047..94bba4553130 100644
> > --- a/tools/testing/selftests/proc/proc-maps-race.c
> > +++ b/tools/testing/selftests/proc/proc-maps-race.c
> > @@ -202,11 +202,11 @@ static void print_first_lines(char *text, int nr)
> >                 int offs = end - text;
> >
> >                 text[offs] = '\0';
> > -               printf(text);
> > +               printf("%s", text);
> >                 text[offs] = '\n';
> >                 printf("\n");
> >         } else {
> > -               printf(text);
> > +               printf("%s", text);
> >         }
> >  }
> >
> > @@ -221,7 +221,7 @@ static void print_last_lines(char *text, int nr)
> >                 nr--;
> >                 start--;
> >         }
> > -       printf(start);
> > +       printf("%s", start);
> >  }
> >
> >  static void print_boundaries(const char *title, FIXTURE_DATA(proc_maps_race) *self)
> > --
> > 2.43.0
> >

Thank you for the review and Acked-by.
I will add the Fixes tag and resend as V2 shortly.

Regards,
Sukrut.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-04 21:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-03 20:47 [PATCH] selftests/proc: Fix string literal warning in proc-maps-race.c Sukrut Heroorkar
2025-08-04 19:47 ` Suren Baghdasaryan
2025-08-04 21:48   ` sukrut heroorkar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®