diff --git a/src/utils.c b/src/utils.c index 2c553b4a8..6e8a543d1 100644 --- a/src/utils.c +++ b/src/utils.c @@ -131,15 +131,19 @@ void amountToString(const uint8_t *amount, uint8_t amount_len = strnlen(tmp_buffer, sizeof(tmp_buffer)); uint8_t ticker_len = strnlen(ticker, MAX_TICKER_LEN); - memcpy(out_buffer, ticker, MIN(out_buffer_size, ticker_len)); - if (ticker_len > 0) { + if (ticker_len > 0 && out_buffer_size > ticker_len + 1) { + memcpy(out_buffer, ticker, ticker_len); out_buffer[ticker_len++] = ' '; } + if (out_buffer_size < ticker_len) { + THROW(EXCEPTION_OVERFLOW); + } + if (adjustDecimals(tmp_buffer, amount_len, out_buffer + ticker_len, - out_buffer_size - ticker_len - 1, + out_buffer_size - ticker_len, decimals) == false) { THROW(EXCEPTION_OVERFLOW); }