Skip to content

Commit 81c6ee6

Browse files
Replace usages of sprintf with snprintf
1 parent 9ad37cc commit 81c6ee6

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

Controllers/DygmaRaiseController/DygmaRaiseController.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void DygmaRaiseController::SendDirect(std::vector<RGBColor>colors, size_t led_nu
6565
/*-----------------------------------------------------*\
6666
| Set up led theme packet |
6767
\*-----------------------------------------------------*/
68-
sprintf(serial_buf,"led.theme");
68+
snprintf(serial_buf, MAX_LEN, "led.theme");
6969
int actual_length=9;
7070

7171
/*-----------------------------------------------------*\
@@ -77,20 +77,20 @@ void DygmaRaiseController::SendDirect(std::vector<RGBColor>colors, size_t led_nu
7777
int g = RGBGetGValue(colors[led_idx]);
7878
int b = RGBGetBValue(colors[led_idx]);
7979

80-
sprintf(serial_buf+actual_length," %d",r);
80+
snprintf(serial_buf + actual_length, MAX_LEN - actual_length, " %d", r);
8181
actual_length += val_char_len(r) + 1;
8282

83-
sprintf(serial_buf+actual_length," %d",g);
83+
snprintf(serial_buf + actual_length, MAX_LEN - actual_length, " %d", g);
8484
actual_length += val_char_len(g) + 1;
8585

86-
sprintf(serial_buf+actual_length," %d",b);
86+
snprintf(serial_buf + actual_length, MAX_LEN - actual_length, " %d", b);
8787
actual_length += val_char_len(b) + 1;
8888
}
8989

9090
/*-----------------------------------------------------*\
9191
| Add the final newline |
9292
\*-----------------------------------------------------*/
93-
sprintf(serial_buf+actual_length,"\n");
93+
snprintf(serial_buf + actual_length, MAX_LEN - actual_length, "\n");
9494
actual_length++;
9595

9696
/*-----------------------------------------------------*\

Controllers/RobobloqLightStripController/RobobloqLightStripController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ bool RobobloqLightStripController::RequestDeviceInfo()
405405
char uuid_buf[17];
406406
for(int i = 0; i < 8; i++)
407407
{
408-
sprintf(uuid_buf + (i * 2), "%02x", data[12 + i]);
408+
snprintf(uuid_buf + (i * 2), sizeof(uuid_buf) - (i * 2), "%02x", data[12 + i]);
409409
}
410410
this->uuid = std::string(uuid_buf);
411411

0 commit comments

Comments
 (0)