Replace usages of sprintf with snprintf

master
Adam Honse 2 months ago
parent 9ad37cc98f
commit 81c6ee6270

@ -65,7 +65,7 @@ void DygmaRaiseController::SendDirect(std::vector<RGBColor>colors, size_t led_nu
/*-----------------------------------------------------*\ /*-----------------------------------------------------*\
| Set up led theme packet | | Set up led theme packet |
\*-----------------------------------------------------*/ \*-----------------------------------------------------*/
sprintf(serial_buf,"led.theme"); snprintf(serial_buf, MAX_LEN, "led.theme");
int actual_length=9; int actual_length=9;
/*-----------------------------------------------------*\ /*-----------------------------------------------------*\
@ -77,20 +77,20 @@ void DygmaRaiseController::SendDirect(std::vector<RGBColor>colors, size_t led_nu
int g = RGBGetGValue(colors[led_idx]); int g = RGBGetGValue(colors[led_idx]);
int b = RGBGetBValue(colors[led_idx]); int b = RGBGetBValue(colors[led_idx]);
sprintf(serial_buf+actual_length," %d",r); snprintf(serial_buf + actual_length, MAX_LEN - actual_length, " %d", r);
actual_length += val_char_len(r) + 1; actual_length += val_char_len(r) + 1;
sprintf(serial_buf+actual_length," %d",g); snprintf(serial_buf + actual_length, MAX_LEN - actual_length, " %d", g);
actual_length += val_char_len(g) + 1; actual_length += val_char_len(g) + 1;
sprintf(serial_buf+actual_length," %d",b); snprintf(serial_buf + actual_length, MAX_LEN - actual_length, " %d", b);
actual_length += val_char_len(b) + 1; actual_length += val_char_len(b) + 1;
} }
/*-----------------------------------------------------*\ /*-----------------------------------------------------*\
| Add the final newline | | Add the final newline |
\*-----------------------------------------------------*/ \*-----------------------------------------------------*/
sprintf(serial_buf+actual_length,"\n"); snprintf(serial_buf + actual_length, MAX_LEN - actual_length, "\n");
actual_length++; actual_length++;
/*-----------------------------------------------------*\ /*-----------------------------------------------------*\

@ -405,7 +405,7 @@ bool RobobloqLightStripController::RequestDeviceInfo()
char uuid_buf[17]; char uuid_buf[17];
for(int i = 0; i < 8; i++) for(int i = 0; i < 8; i++)
{ {
sprintf(uuid_buf + (i * 2), "%02x", data[12 + i]); snprintf(uuid_buf + (i * 2), sizeof(uuid_buf) - (i * 2), "%02x", data[12 + i]);
} }
this->uuid = std::string(uuid_buf); this->uuid = std::string(uuid_buf);

Loading…
Cancel
Save