Skip to content

Commit 8559dba

Browse files
Potential fix for code scanning alert no. 86: Potentially overrunning write
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent e2e895d commit 8559dba

File tree

1 file changed

+4
-4
lines changed
  • libraries/ESP32/examples/FreeRTOS/Mutex

1 file changed

+4
-4
lines changed

libraries/ESP32/examples/FreeRTOS/Mutex/Mutex.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ void Task(void *pvParameters) { // This is a task.
7272
int new_value = random(1000);
7373

7474
char str0[32];
75-
sprintf(str0, " %d <- %d |", shared_variable, new_value);
75+
snprintf(str0, sizeof(str0), " %d <- %d |", shared_variable, new_value);
7676
char str1[32];
77-
sprintf(str1, " | %d <- %d", shared_variable, new_value);
77+
snprintf(str1, sizeof(str1), " | %d <- %d", shared_variable, new_value);
7878
Serial.printf("%s\n", task_num ? str0 : str1);
7979

8080
shared_variable = new_value;
8181
delay(random(100)); // wait random time of max 100 ms - simulating some computation
8282

83-
sprintf(str0, " R: %d |", shared_variable);
84-
sprintf(str1, " | R: %d", shared_variable);
83+
snprintf(str0, sizeof(str0), " R: %d |", shared_variable);
84+
snprintf(str1, sizeof(str1), " | R: %d", shared_variable);
8585
Serial.printf("%s\n", task_num ? str0 : str1);
8686
//Serial.printf("Task %d after write: reading %d\n", task_num, shared_variable);
8787

0 commit comments

Comments
 (0)