File: bug-22593.c

package info (click to toggle)
avr-libc 1%3A1.6.2.cvs20080610-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 14,848 kB
  • ctags: 55,619
  • sloc: ansic: 92,267; asm: 6,692; sh: 4,131; makefile: 2,481; python: 976; pascal: 426; perl: 116
file content (41 lines) | stat: -rw-r--r-- 850 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* bug #22593: vfscanf improperly scans string parameters with a width
   option by 1 character
   $Id: bug-22593.c,v 1.1.2.2 2008/03/18 13:30:06 dmix Exp $	*/

/* Seems, this is duplication of bug #19079: sscanf %s eats 1 char too much
 */

#include <stdio.h>
#include <string.h>

#ifndef	__AVR__
# define sscanf_P	sscanf
# define PSTR(s)	(s)
#else
# include <avr/pgmspace.h>
#endif

int main ()
{
    char s1[5], s2[5];
    int result;
    
    s1[0] = 0;
    s2[0] = 0;

    result = sscanf_P (",ABCD,EFGH,", PSTR (",%4s,%4s,"), s1, s2);
    if (result != 2)
	return __LINE__;
    if (strcmp (s1, "ABCD") || strcmp (s2, "EFGH"))
	return __LINE__;

    s1[0] = 0;
    s2[0] = 0;
    result = sscanf_P (",ABCD,EFGH,", PSTR (",%3s,%3s,"), s1, s2);
    if (result != 1)
	return __LINE__;
    if (strcmp (s1, "ABC"))
	return __LINE__;

    return 0;
}