sprintf causes memory overlap

Hello,

Project secure boot loader S140, SDK 16.0, nRF52840.

This line of code causes compile/LInker errors in my project. I guess I need to adjust memory start address in my Linker section placement macros (?). But I'm not sure which value should be changed to what. Please help.

sprintf(hex, "%2X", ble_addr.addr[1]);

Here is the complete error message:

Building ‘secure_bootloader_ble_s140_pca10056’ from solution ‘secure_bootloader_ble_s140_pca10056’ in configuration ‘Release’
  Compiling ‘nrf_dfu_ble.c’
    ignoring return value of 'malloc' declared with attribute 'warn_unused_result' [-Wunused-result]
  Linking secure_bootloader_ble_s140_pca10056.elf
     section .mbr_params_page VMA [00000000000fe000,00000000000fefff] overlaps section .text VMA [00000000000f83d4,00000000000fe1db]
     section .crypto_data VMA [00000000000fe1dc,00000000000fe1e3] overlaps section .mbr_params_page VMA [00000000000fe000,00000000000fefff]
    Build failed
Build failed

Thanks.

Parents
  • I had to replay the sprintf functionality to following code and it solved the issue for me. But still it may be essential for somebody else to use sprintf.

    // Convert into hex string
    int num; char hx0, hx1;    
    for (int i=0; i<2; i++){
        num = ble_addr.addr[1-i];
        hx0 = (num >> 4) < 10 ? (num >> 4) + '0' : (num >> 4) - 10 + 'A';
        hx1 = (num & 0x0F) < 10 ? (num & 0x0F) + '0' : (num & 0x0F) - 10 + 'A';
        device_name[4+i*2] = hx0;
        device_name[5+i*2] = hx1;
    }

Reply
  • I had to replay the sprintf functionality to following code and it solved the issue for me. But still it may be essential for somebody else to use sprintf.

    // Convert into hex string
    int num; char hx0, hx1;    
    for (int i=0; i<2; i++){
        num = ble_addr.addr[1-i];
        hx0 = (num >> 4) < 10 ? (num >> 4) + '0' : (num >> 4) - 10 + 'A';
        hx1 = (num & 0x0F) < 10 ? (num & 0x0F) + '0' : (num & 0x0F) - 10 + 'A';
        device_name[4+i*2] = hx0;
        device_name[5+i*2] = hx1;
    }

Children
No Data
Related