device: misc cleanup

use snprintf "just in case" where appropriate
consistently use unsigned for temp values
pass std::string by const ref rather than by value
add length check (which can't happen in practice) for memcpy
This commit is contained in:
moneromooo-monero
2018-06-23 15:26:55 +01:00
parent 3b4dec2d12
commit 41e9cab4e1
3 changed files with 14 additions and 12 deletions

View File

@@ -187,7 +187,7 @@ namespace hw {
void device_ledger::logCMD() {
if (apdu_verbose) {
char strbuffer[1024];
sprintf(strbuffer, "%.02x %.02x %.02x %.02x %.02x ",
snprintf(strbuffer, sizeof(strbuffer), "%.02x %.02x %.02x %.02x %.02x ",
this->buffer_send[0],
this->buffer_send[1],
this->buffer_send[2],
@@ -203,7 +203,7 @@ namespace hw {
void device_ledger::logRESP() {
if (apdu_verbose) {
char strbuffer[1024];
sprintf(strbuffer, "%.02x%.02x ",
snprintf(strbuffer, sizeof(strbuffer), "%.02x%.02x ",
this->buffer_recv[this->length_recv-2],
this->buffer_recv[this->length_recv-1]
);
@@ -295,7 +295,7 @@ namespace hw {
unsigned int device_ledger::exchange(unsigned int ok, unsigned int mask) {
LONG rv;
int sw;
unsigned int sw;
ASSERT_T0(this->length_send <= BUFFER_SEND_SIZE);
logCMD();