Skip to contentSkip to conversation

selftests/proc: Fix string literal warning in proc-maps-race.c

PATCH Superseded Sukrut Heroorkar 2 participants 3 messages Aug 3, 2025 – Aug 4, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/proc: Fix string literal warning in proc-maps-race.c

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.

---
 tools/testing/selftests/proc/proc-maps-race.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/proc/proc-maps-race.c +3 -3
index 66773685a047..94bba4553130 100644
@@ -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)
Signature · 1 line
2.43.0
Acked-by on v1 1/1
#1 lore raw
Quoted 15 lines · Sukrut Heroorkar

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);
      |         ^~~~~~
Quoted 6 lines

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")

Quoted 2 lines

Thanks,
Suren.

Quoted 34 lines
---
 tools/testing/selftests/proc/proc-maps-race.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/proc/proc-maps-race.c +3 -4
index 66773685a047..94bba4553130 100644
@@ -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

#2 lore raw

Hi Suren,

Quoted 67 lines · Suren Baghdasaryan
Quoted 15 lines · Sukrut Heroorkar

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);
      |         ^~~~~~
Quoted 6 lines

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")

Quoted 2 lines

Thanks,
Suren.

Quoted 30 lines
---
 tools/testing/selftests/proc/proc-maps-race.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/proc/proc-maps-race.c +3 -3
index 66773685a047..94bba4553130 100644
@@ -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);
 }
 
Quoted 4 lines
Quoted 4 lines
tools/testing/selftests/proc/proc-maps-race.c +0 -1
 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.