I have a case for sscanf that could not handle all the formats:
rc = sscanf(buf, "sig:%s\ncallid:%s\ncallname:%s\ngroup:%d\npgtype:%d\n",
(char *) (&parms->sig), (char *) (&parms->callid),
(char *) (&parms->callname),&parms->group_num,(&parms->msg_type));
what's inside the buf:
"sig:Arc621\ncallid:anonymous\ncallname:Anonymous\ngroup:2\npgtype:2\n"
The matching failed after the first "%d" - the issue in sscanf is:
- A: the next character in format is '\n' - which is not treated as a white space (only blank and '\t' are treated )
- B: the next character in input line is '\n' - which is a white space so it is thrown away then read next non-white space which is 'p' in the above example.
A and B did not match so the function sscanf returned without trying to match others.
I have a tempory work around is all white spaces are treated same in
_io_scanline_format_ignore_white_space, _io_scanline_ignore_white_space, and _io_scanline as well.
Hi David_Wu,
first of all, this is snapped from _io_sscanf function:
va_start(ap, format_ptr);
result = _io_scanline(str_ptr, (char _PTR_)format_ptr, ap);
va_end(ap);
It calls _io_scanline. How come your problem does not appear with _io_scanline ?
Regards,
MartinK
Hi MartinK,
My problem is exactly happended in _io_scanline(). And the fix is also in _io_scanline() and
_io_scanline_format_ignore_white_space().
char _io_scanline_format_ignore_white_space
(
/* [IN/OUT] the address of the string pointer */
registerchar _PTR_ _PTR_ s_ptr,
/* [OUT] the number of characters skipped */
register_mqx_uint _PTR_ count
)
{
/* Body */
registerchar c;
*count = 0;
c = **s_ptr;
//while ( (c == ' ') || (c == '\t') ) {//WMQ change - ignore all white spaces
while ( (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r') || (c =='\v') || (c == '\f') ) {
c = *(++*s_ptr);
(*count)++;
}
/* Endwhile */
return (c);
}
/* Endbody */
_mqx_int _io_scanline
(
/* [IN] the input line of ascii data*/
char _PTR_ line_ptr,
/* [IN] fmt first points to the format string */
char _PTR_ format,
/* [IN] the list of parameters */
va_list args_ptr
)
{
/* Body */
char suppress_field;
register_mqx_int c;
register_mqx_uint n;
char _PTR_ sptr = NULL;
_mqx_int sign;
uint_32 val;
_mqx_int width;
_mqx_int numtype; /* used to indicate bit size of argument */
register_mqx_int number_of_chars;
_mqx_uint temp;
_mqx_uint base;
pointer tmp_ptr;
#if MQX_INCLUDE_FLOATING_POINT_IO
double dnum;
#endif
n = 0;
number_of_chars = 0;
while ((c = *format++) != 0) {
width = 0;
/*
** skip white space in format string, and any in input line
*/
//if ( (c == ' ') || (c == '\t') ) { //WMQ change - ignore all white spaces
if ( (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r') || (c =='\v') || (c == '\f')) {
if ( ! _io_scanline_format_ignore_white_space( (
char _PTR_ _PTR_)&format, &temp ) ) {
......
Hi David_Wu,
Your fix has been integrated to MQX and will be available in MQX 4.0.2 release.
Thank you.
Regard
Martin
Hello David_Wu,
thank you for sharing your fix and reporting the problem ! It has been reported to the team
Regards,
MartinK