ChibiOs: chibios-code-r17592-trunk - most recent as of today - including [r17492] Fixed problem with initialization (tentative).
Hardware: STM32F411CE Blackpill 25MHz
OS: RT
When using chsnscanf, I encountered a problem reading a single "0" with fmt = "%x".
It works OK for a single "9" and fmt = "%x" and more inputs.
See below!
Code: Select all
/*
* Flaw in chsnscanf reading a single "0" with fmt = "%x"
* Compiled vs trunk version chibios-code-r17592-trunk
*/
#include "hal.h"
#include "ch.h"
/* include $(CHIBIOS)/os/hal/lib/streams/streams.mk in makefile */
#include "chscanf.h"
int res;
int data;
char str0[] = "0";
char str9[] = "9";
char str0x0[] = "0x0";
char str00[] = "00";
#define countof(x) (sizeof(x)/sizeof(x[0]))
int main(void) {
data = 0x55; // dummy fill
/* Flaw: res = 0, data unchanged (0x55). */
res = chsnscanf(str0, countof(str0), "%x", &data);
data = 0x55;
/* OK: res = 1, data = 9. */
res = chsnscanf(str9, countof(str9), "%x", &data);
data = 0x55;
/* OK: res = 1, data = 0. */
res = chsnscanf(str00, countof(str00), "%x", &data);
data = 0x55;
/* OK: res = 1, data = 0. */
res = chsnscanf(str0x0, countof(str0x0), "%x", &data);
return 0;
}
Best regards,
Wolf