blob: 8bcb10accb54e558f17aa2d97d3b6d2079409df5 (
plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/* PR tree-optimization/51315 */
/* Reported by Jurij Smakov <jurij@wooyd.org> */
typedef unsigned int size_t;
extern void *memcpy (void *__restrict __dest,
__const void *__restrict __src, size_t __n)
__attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
extern size_t strlen (__const char *__s)
__attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
typedef short int int16_t;
typedef int int32_t;
extern void abort (void);
int a;
static void __attribute__ ((noinline,noclone))
do_something (int item)
{
a = item;
}
int
pack_unpack (char *s, char *p)
{
char *send, *pend;
char type;
int integer_size;
send = s + strlen (s);
pend = p + strlen (p);
while (p < pend)
{
type = *p++;
switch (type)
{
case 's':
integer_size = 2;
goto unpack_integer;
case 'l':
integer_size = 4;
goto unpack_integer;
unpack_integer:
switch (integer_size)
{
case 2:
{
union
{
int16_t i;
char a[sizeof (int16_t)];
}
v;
memcpy (v.a, s, sizeof (int16_t));
s += sizeof (int16_t);
do_something (v.i);
}
break;
case 4:
{
union
{
int32_t i;
char a[sizeof (int32_t)];
}
v;
memcpy (v.a, s, sizeof (int32_t));
s += sizeof (int32_t);
do_something (v.i);
}
break;
}
break;
}
}
return (int) *s;
}
int
main (void)
{
int n = pack_unpack ("\200\001\377\376\035\300", "sl");
if (n != 0)
abort ();
return 0;
}
|