Skip to content

Commit

Permalink
target: Replace remaining sprintf calls with snprintf
Browse files Browse the repository at this point in the history
* These cases in efm32, sam3x, stm32l0 store a string into bounded priv_storage
* Pass its size as second argument, as done everywhere else
  • Loading branch information
ALTracer committed May 13, 2024
1 parent 7933ed3 commit bd8fd9e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/target/efm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,8 @@ bool efm32_aap_probe(adiv5_access_port_s *ap)
DEBUG_INFO("EFM32: AAP STATUS=%08" PRIx32 "\n", adiv5_ap_read(ap, AAP_STATUS));

efm32_aap_priv_s *priv_storage = calloc(1, sizeof(*priv_storage));
sprintf(priv_storage->aap_driver_string, "EFM32 Authentication Access Port rev.%hu", aap_revision);
snprintf(priv_storage->aap_driver_string, sizeof(priv_storage->aap_driver_string),
"EFM32 Authentication Access Port rev.%hu", aap_revision);
t->driver = priv_storage->aap_driver_string;
t->regs_size = 0;

Expand Down
6 changes: 3 additions & 3 deletions src/target/sam3x.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ bool samx7x_probe(target_s *t)
sam_add_flash(t, SAMX7X_EEFC_BASE, 0x00400000, priv_storage->descr.flash_size);
target_add_commands(t, sam_cmd_list, "SAMX7X");

sprintf(priv_storage->sam_variant_string, "SAM%c%02d%c%d%c", priv_storage->descr.product_code,
priv_storage->descr.product_id, priv_storage->descr.pins, priv_storage->descr.density,
priv_storage->descr.revision);
snprintf(priv_storage->sam_variant_string, sizeof(priv_storage->sam_variant_string), "SAM%c%02d%c%d%c",
priv_storage->descr.product_code, priv_storage->descr.product_id, priv_storage->descr.pins,
priv_storage->descr.density, priv_storage->descr.revision);

t->driver = priv_storage->sam_variant_string;
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/target/stm32l0.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ bool stm32l0_probe(target_s *const target)
const uint32_t nvm = stm32lx_nvm_phys(target);
const bool protected =
(target_mem32_read32(target, STM32Lx_NVM_OPTR(nvm)) & STM32Lx_NVM_OPTR_RDPROT_M) != STM32Lx_NVM_OPTR_RDPROT_0;
sprintf(priv_storage->stm32l_variant, "%s%s", target->driver, protected ? " (protected)" : "");
snprintf(priv_storage->stm32l_variant, sizeof(priv_storage->stm32l_variant), "%s%s", target->driver,
protected ? " (protected)" : "");
target->driver = priv_storage->stm32l_variant;

if (protected) {
Expand Down

0 comments on commit bd8fd9e

Please sign in to comment.