source: CIVL/examples/svcomp17/20051113-1.c_false-valid-memtrack.c@ 1aaefd4

main test-branch
Last change on this file since 1aaefd4 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.6 KB
Line 
1extern void __VERIFIER_error() __attribute__ ((__noreturn__));
2
3#include <stdlib.h>
4
5extern void *malloc(__SIZE_TYPE__);
6extern void *memset(void *, int, __SIZE_TYPE__);
7typedef struct
8{
9 short a;
10 unsigned short b;
11 unsigned short c;
12 unsigned long long Count;
13 long long Count2;
14} __attribute__((packed)) Struct1;
15
16typedef struct
17{
18 short a;
19 unsigned short b;
20 unsigned short c;
21 unsigned long long d;
22 long long e;
23 long long f;
24} __attribute__((packed)) Struct2;
25
26typedef union
27{
28 Struct1 a;
29 Struct2 b;
30} Union;
31
32typedef struct
33{
34 int Count;
35 Union List[1];
36} __attribute__((packed)) Struct3;
37
38unsigned long long Sum (Struct3 *instrs) __attribute__((noinline));
39unsigned long long Sum (Struct3 *instrs)
40{
41 unsigned long long count = 0;
42 int i;
43
44 for (i = 0; i < instrs->Count; i++) {
45 count += instrs->List[i].a.Count;
46 }
47 return count;
48}
49long long Sum2 (Struct3 *instrs) __attribute__((noinline));
50long long Sum2 (Struct3 *instrs)
51{
52 long long count = 0;
53 int i;
54
55 for (i = 0; i < instrs->Count; i++) {
56 count += instrs->List[i].a.Count2;
57 }
58 return count;
59}
60static void dummy_abort(void)
61{
62}
63int main() {
64 Struct3 *p = malloc (sizeof (int) + 3 * sizeof(Union));
65 memset(p, 0, sizeof(int) + 3*sizeof(Union));
66 p->Count = 3;
67 p->List[0].a.Count = 555;
68 p->List[1].a.Count = 999;
69 p->List[2].a.Count = 0x101010101ULL;
70 p->List[0].a.Count2 = 555;
71 p->List[1].a.Count2 = 999;
72 p->List[2].a.Count2 = 0x101010101LL;
73 if (Sum(p) != 555 + 999 + 0x101010101ULL)
74 dummy_abort();
75 if (Sum2(p) != 555 + 999 + 0x101010101LL)
76 dummy_abort();
77 p = NULL;
78 return 0;
79}
Note: See TracBrowser for help on using the repository browser.