aboutsummaryrefslogtreecommitdiffstats
path: root/test/testFuncs2.c
blob: b382b8bb7f000974090be248bd4d3a2497c28ea0 (plain) (blame)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/*first line intentionally left blank*/
/*********************************************************************************************************************/
/*inclusion directives*/
#include "testFuncs2.h"
#if 0
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <signal.h>
#include <time.h>
#endif
/*********************************************************************************************************************/
/*macro and definitions*/
typedef const* INTPTR;
/*clang wont let it through*/
#if 0
typedef int dummytypedef;
#endif

#if 0
/*clang wont let it through*/
/*for 5.3*/
typedef gaga incompletearr1;
#endif
/*gibber/*gabber*/
#define XMACRO Y

#define ABSOLUTE(X) (((X) >= 0) ? (X) : -(X))
#define ABSOLUTE2(X) ((X >= 0) ? X : -X)
#define ABSOLUTE3(XMACRO) (((XMACRO) <= 0) ? (XMACRO) : -(XMACRO))
#define MINUS(X,Y) ((X) - (Y))
#define PRINT(bubba) printf(#bubba "%d\n", bubba)
#define LOCO i##nt
#define LOCO2 #LOCO2
#define LOCO3(bubba) printf(#bubba "%d\n", bu##bba)
#define DEFINEVAR(X,Y) int X##Y
#define PI 3.14
#define PI2 (a)
#define charchar char

#define __FILE__
#define __DATE__
#define __TIME__
#undef __STDC__
#undef __FILE__

#define int int
#undef int

#if defined PI2
#endif

#if 0
#if defined LOCO2
#endif
#endif

#if defined LOCOLUPO
#endif

#if defined LOCO
#endif

#if defined(LOCO)
#endif

#define DEFINED defined
#if DEFINED(X)
#endif

#if defined LOCOLUPO || LOCO
#endif


#define LOCOLUPO
#if 1
#undef LOCOLUPO
#endif

#define START 0x80000000
#define END 0xFFFFFFFF
#define LEN 0x80000000
#if ((START + LEN) > END)
#if 0
#error Buffer Overrun
#endif
/* OK because START and LEN are unsigned long */
#endif
#if (((END - START) - LEN) < 0)
#if 0
#error Buffer Overrun
#endif
/* Not OK: subtraction result wraps around to 0xFFFFFFFF */
#endif
/*********************************************************************************************************************/
/*Globals*/
int incompletearr1[];
int incompletearr2[];

int dudu;
int bubu;
int fufu;
double badboy = 0.0;

int hiddenvisibility;

int incompletearr1[10];

union u3;
union u4;

union u3
{
  int ua;
  char ub;
};

union yizzy
{
  int ua;
  char ub;
};

double yizzy;

double u3;
double ua;

int s10;

struct s10;
struct s11;

struct s10
{
  int sa[10];
  char sb;
  int sc;
};

const unsigned int cint = 0xFFFFFFFF;

/*********************************************************************************************************************/
/*functions go here.*/
static void test33(void)
{

  short int a;
  long int b;
  int sum;

  int hiddenvisibility;

  sum = dudu + bubu + fufu;

  MINUS(a, b);
  //MINUS(a);

  b = (int)a;

  /* contrast the above START + LEN with the following */
  if ((START + LEN) > END)
  {
    //error ("Buffer overrun");
    /* Not OK: START + LEN wraps around to 0x0000
    due to unsigned int arithmetic */
  }
}

void testfunc1(void)
{
  unsigned char a;
  unsigned char b;
  char c;
  int sum;
  charchar d;

  sum = sum + dudu + fufu;

  b =  a;
  c = 123;
  d = 123;
  c = 'c';
  c = "c";
  b = 'b';
  b = "b";
  a = 123;
  c = '\n';

  ;;;;
  ;/*comment*/
  ; /*comment*/

  c = '5';
}

#if CRAZYMACRO < 0
#endif

testfunc2(void)
{
  int a;
  int b;
  int sum;

  sum = a + b + dudu;
}

void testfunc3()
{
  int a;
  int b;
  int c;

#define LUPO wolf

#if 1
  int abcdefghijklmnopqrstuvwxyz1234567890;
  int abcdefghijklmnopqrstuvwxyz12345678902;
#endif

  /*do stuff*/
}

int testfunc6(void)
{
  int a;
  int b;
  //return ();
}

int testfunc7(void)
{
  int a;
  int b;
  //return;
}

int testfunc8(void)
{
  int a[10];
  int b[10];

  int* p;

  p = &a[0];

#undef LUPO

  int i;
  int sum;
  int sum2;
  int garbage;
  int garbage2;

  for (i = 0; i < 10; ++i)
  {
    sum += *(a + i);
    sum2 += *(p + i);
    //garbage = *(a - b);
  }

  for (i = 10; i < 1; i++)
  {
    sum += *(a - i);
    sum2 += *(p - i);
    //garbage2 = *(p - a);
  }
}

void testfunc9(void)
{
  int** p1;
  int*** p2;

  int* pointer1;
  double d2;

  pointer1 = &d2;

  struct
  {
    int* sp1;
    int** sp2;
    int*** sp3;
  };

  struct s* ps1;
  /*these two should not be tagged by 18.1 since they are pointers(to pointers) to an incomplete type. the pointer itself is a complete type.*/
  struct s** ps2;
  struct s*** ps3;

  INTPTR *const* const fedupp1;

  int ** (*pfunc1)();
  int crazycast1 = (int)pfunc1;
  int crazycast2;
  pfunc1 = (int ** (*)())crazycast2;
  int ** (**pfunc2)();
  pfunc2 = pfunc1;
  pfunc2 = (int ** (*)())pfunc1;
  int ** (***pfunc3)();
  int *** (**pfunc4)();
  int ** (**pfunc5)(int**, int**);
  int ** (**pfunc6)(int**, int***);
}

void testfunc10 (int ** (**p5)(int**, int**), int ** (**p6)(int**, int***))
{

}

void testfunc11(void)
{
  long int a;
  double dd;
  short unsigned int b;
  short int* p1;
  long int* p2;
  int normalint;

  p2 = (long int*)p1;
  p1 = (short int*)p2;
  b = a;
  dd = b;
  normalint = a;
}

void testfunc12(void)
{
  const char* stringlit = "date should be in the form ??-??-??";

  short unsigned int port = 0x005aU;
  unsigned char portchar = 0x005aU;
  short unsigned int resultshort;
  const unsigned char charconst = 4U;
  unsigned int resultlong;
  unsigned int mode;
  resultshort = (~port) >> 4U;
  resultshort = port << 4U;
  resultshort = (short unsigned int)(port << 4U);
  resultshort = (short signed int)(port << 4U);
  resultshort = portchar << 4U;
  resultshort = (unsigned char)(portchar << charconst);
  resultshort = ((short unsigned int)(~port)) >> 4U;
  /*should not be tagged by 10.1\2*/
  resultlong = ((int)(~(int)port)) >> 4U;

  /*not comliant*/
  resultlong = ((port << 4U) & mode) >> 6U;
  /*compliant*/
  resultlong = ((unsigned int)((unsigned int)port << 4U) & mode) >> 6U;
}

/*the test are from the misrac doc for 11.5*/
void testfunc13(void)
{
  int x;
  int * const cpi = &x; /* const pointer */
  int * const * pcpi; /* pointer to const pointer */
  const int * * ppci; /* pointer to pointer to const */
  int * * ppi;
  const int * pci; /* pointer to const */
  volatile int * pvi; /* pointer to volatile */
  int * pi;
  pi = cpi; /* Compliant - no conversion
no cast required */
  pi = (int *)pci; /* Not compliant */
  pi = (int *)pvi; /* Not compliant */
  ppi = (int * *)pcpi; /* Not compliant */
  ppi = (int * *)ppci; /* Not compliant */
}

void testfunc14(void)
{
  char a;
  long int b;
  long int b2;
  double c;
  float d;
  long double e;
  a = (int)b;
  a = (int)(b + b2);
  a = b + b2;
  a = b++;
  if ((int)(b + b2))
  {
    /*somethi/*ng*/
  }

  a = c;
  c = b;
  d = c;
  d = e;
}

void testfunc15 (void)
{
  int a[10];

  a[1] = 041;
  a[2] = 052;
}

void testfunc16(int* p1, int* p2, int* const p3, const int* p4, int* p5)
{
  if (*p1 > 100)
  {
    /*do something*/
  }

  if (*p5 > 100)
  {
    /*do something*/
  }

  p5++;
  p5 = p5 + 10;

  *p2++;
  *p2 = *p2 + 100;

  if (*p3 > 1000)
  {
    /*do something else*/
  }

  if (*p4 < 100)
  {
    /*yet another task*/
  }
}

/*********************************************************************************************************************/
/*last line intentionally left blank.*/