File: bug-22800.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 (56 lines) | stat: -rw-r--r-- 1,202 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* bug #22800: sprintf() expands a 128char string parameter incorrectly
   $Id: bug-22800.c,v 1.1.2.2 2008/04/03 11:19:52 dmix Exp $
   
   This bug is marked as INVALID.  It is take place with avr-libc 1.4 only,
   which is not supported now.  Avr-libc 1.6 is correct.
 */

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

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


char buffer[210], string[200];
char tmp[] = "123";

int main ()
{
    int i;

    /* This is the bug report code.	*/
    for (i = 0; i < 129; i++)
	string[i] = 'B';
    sprintf (buffer, "%s%s", string, tmp);
    
    if (strcmp_P (buffer, PSTR ("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"  /* 32*B */
				"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"  /* 32*B */
				"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"  /* 32*B */
				"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"  /* 32*B */
				"B123")))
    {
	return __LINE__;
    }

#if	!defined(__AVR__) || (RAMEND >= 0x45F)
    /* Check the size > 255.	*/
    {
	char s[260];
	char t[sizeof(s)];

	memset (s, 'A', sizeof(s));
	s[sizeof(s) - 1] = 0;
	memset (t, 'B', sizeof(t));
	sprintf (t, "%s", s);
	
	if (strcmp (s, t)) return __LINE__;
    }
#endif
    
    return 0;
}