Macaulay2 Engine
Loading...
Searching...
No Matches

◆ main()

int main ( int argc,
char ** argv )

Definition at line 70 of file overflow-test.cpp.

71{
72 int i, j;
73 int s = s0;
74 s0 = s; // use s at least once
75 // use one of these to see if overflows are really detected. Each one
76 // should generate an overflow and a program termination.
77 if (argc > 1)
78 {
79 if (0 == strcmp(argv[1], "sub"))
80 {
81 printf("test failed, result %x\n",
82 (unsigned int)safe::sub(0x80000000, 1 - x + x));
83 exit(1);
84 }
85 else if (0 == strcmp(argv[1], "add"))
86 {
87 printf("test failed, result %x\n",
88 (unsigned int)safe::add(0x7fffffff, 1 - x + x));
89 exit(1);
90 }
91 else if (0 == strcmp(argv[1], "mult"))
92 {
93 printf("test failed, result %x\n",
94 (unsigned int)safe::mult(0x8000, 0x10000 - x + x));
95 exit(1);
96 }
97 else if (0 == strcmp(argv[1], "div"))
98 {
99 printf("test failed, result %x\n",
100 (unsigned int)safe::div(0x80000000, -1 - x + x));
101 exit(1);
102 }
103 else if (0 == strcmp(argv[1], "minus"))
104 {
105 printf("test failed, result %x\n",
106 (unsigned int)safe::minus(0x80000000 - x + x));
107 exit(1);
108 }
109 else if (0 == strcmp(argv[1], "throw"))
110 {
111 safe::ov("throw overflow exception");
112 printf("test failed\n");
113 exit(1);
114 }
115 else
116 {
117 printf("unknown test: %s\n", argv[1]);
118 exit(1);
119 }
120 }
121#define roll 100
122 printf("%lld repetitions\n", (long long)inner * outer * roll);
123 for (i = outer; i > 0; i--)
124 for (j = 0; j < inner; j++)
125 { // 100 times ( == roll, defined above )
126 {
127 stmt;
128 stmt;
129 stmt;
130 stmt;
131 stmt;
132 stmt;
133 stmt;
134 stmt;
135 stmt;
136 stmt; /* 10 times */
137 }
138 {
139 stmt;
140 stmt;
141 stmt;
142 stmt;
143 stmt;
144 stmt;
145 stmt;
146 stmt;
147 stmt;
148 stmt; /* 10 times */
149 }
150 {
151 stmt;
152 stmt;
153 stmt;
154 stmt;
155 stmt;
156 stmt;
157 stmt;
158 stmt;
159 stmt;
160 stmt; /* 10 times */
161 }
162 {
163 stmt;
164 stmt;
165 stmt;
166 stmt;
167 stmt;
168 stmt;
169 stmt;
170 stmt;
171 stmt;
172 stmt; /* 10 times */
173 }
174 {
175 stmt;
176 stmt;
177 stmt;
178 stmt;
179 stmt;
180 stmt;
181 stmt;
182 stmt;
183 stmt;
184 stmt; /* 10 times */
185 }
186 {
187 stmt;
188 stmt;
189 stmt;
190 stmt;
191 stmt;
192 stmt;
193 stmt;
194 stmt;
195 stmt;
196 stmt; /* 10 times */
197 }
198 {
199 stmt;
200 stmt;
201 stmt;
202 stmt;
203 stmt;
204 stmt;
205 stmt;
206 stmt;
207 stmt;
208 stmt; /* 10 times */
209 }
210 {
211 stmt;
212 stmt;
213 stmt;
214 stmt;
215 stmt;
216 stmt;
217 stmt;
218 stmt;
219 stmt;
220 stmt; /* 10 times */
221 }
222 {
223 stmt;
224 stmt;
225 stmt;
226 stmt;
227 stmt;
228 stmt;
229 stmt;
230 stmt;
231 stmt;
232 stmt; /* 10 times */
233 }
234 {
235 stmt;
236 stmt;
237 stmt;
238 stmt;
239 stmt;
240 stmt;
241 stmt;
242 stmt;
243 stmt;
244 stmt; /* 10 times */
245 }
246 }
247}
void size_t s
Definition m2-mem.cpp:271
static int32_t mult(int32_t x, int32_t y, const char *msg)
Definition overflow.hpp:236
static int32_t add(int32_t x, int32_t y, const char *msg)
Definition overflow.hpp:116
static int32_t div(int32_t x, int32_t y, const char *msg)
Definition overflow.hpp:263
static int32_t sub(int32_t x, int32_t y, const char *msg)
Definition overflow.hpp:144
void ov(const char *msg)
Definition overflow.cpp:5
static int32_t minus(int32_t x, const char *msg)
Definition overflow.hpp:185
#define roll
#define stmt
#define outer
volatile int x
volatile int s0
#define inner

References safe::add(), safe::div(), inner, safe::minus(), safe::mult(), outer, safe::ov(), roll, s, s0, stmt, safe::sub(), and x.