Wrong scanf parsing when using scanset

Bug #1879306 reported by Adrien Crucifix
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
New
Undecided
Unassigned

Bug Description

When using Scanset as sscanf format, parsing results may be wrong.
By using %c format, the sscanf behavior is as expected, when Scanset format is used (eg. %[A-Z]), the parsing of the previous argument seems to be altered.

Tested GCC version:
* arm-none-eabi-gcc (GNU MCU Eclipse ARM Embedded GCC, 64-bits) 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204]
* arm-none-eabi-gcc (xPack GNU Arm Embedded GCC, 64-bit) 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]

To reproduce:
#include <stdio.h>

int main(void)
{
    int rc, a, b;
    char c;

    rc = sscanf("12,34,A", "%d,%d,%[A-Z]", &a, &b, &c);
    printf("1) rc:%d, a:%d, b:%d, c:%c\n", rc, a, b, c);

    rc = sscanf("12,34,A", "%d,%d,%c", &a, &b, &c);
    printf("2) rc:%d, a:%d, b:%d, c:%c\n", rc, a, b, c);

    return 0;
}

Output:
With -O0 or -O1 option:
1) rc:3, a:12, b:0, c:A
2) rc:3, a:12, b:34, c:A

With -O2, -O3 or -Os options:
1) rc:3, a:0, b:34, c:A
2) rc:3, a:12, b:34, c:A

Compile option:
-std=gnu99 -c -fno-exceptions -fno-builtin -ffunction-sections -fdata-sections -funsigned-char -MMD -fno-delete-null-pointer-checks -fomit-frame-pointer -g3 -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp

Link option:
-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.