Flaw in chsnscanf reading a single "0" with fmt = "%x" Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
wolf
Posts: 42
Joined: Mon Dec 31, 2012 1:55 pm
Been thanked: 9 times

Flaw in chsnscanf reading a single "0" with fmt = "%x"

Post by wolf »

Hi all!

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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Flaw in chsnscanf reading a single "0" with fmt = "%x"

Post by Giovanni »

Hi,

Fixed in trunk.

Giovanni
wolf
Posts: 42
Joined: Mon Dec 31, 2012 1:55 pm
Been thanked: 9 times

Re: Flaw in chsnscanf reading a single "0" with fmt = "%x"

Post by wolf »

Hi all!

I did a quick test with trunc r17617, seems to work as expexted now.

Many thanks,

regards Wolf
Post Reply