Skip to content

Printf/sprintf not printing leading zeros #12718

@pilotak

Description

@pilotak

Description of defect

Using a following code compiled against os5.15 will produce following output (which is expected)

0C
90
03
00
16
57
4A
48
38
04
37
20
result[24]: 0C90030016574A4838043720

but same code with os6.0.0-alpha3 produces

C
90
3
0
16
57
4A
48
38
4
37
20
result[24]: C

Target(s) affected by this defect ?

Maybe all, i tried it on STM32F303RE

Toolchain(s) (name and version) displaying this defect ?

gcc-arm-none-eabi-9-2019-q4-major

What version of Mbed-os are you using (tag or sha) ?

mbed-os-6.0.0-alpha-3

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

cli: 1.10.1

How is this defect reproduced ?

#include "mbed.h"

const uint8_t id[12] = {
    0x0c, 0x90, 0x03, 0x00, 0x16, 0x57, 0x4a, 0x48, 0x38, 0x04, 0x37, 0x20
};

int main() {
    char str[50] = {0};
    int str_len = 0;

    for (int i = 0; i < 12; i++) {
        printf("%02X\n", id[i]);
        str_len += snprintf(str + str_len, sizeof(str), "%02X", id[i]);
    }

    printf("result[%i]: %s\n", str_len, str);

    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions