@@ -2,7 +2,7 @@ char *malloc(int size);
2
2
3
3
void test1 (int size) {
4
4
char * p = malloc (size);
5
- char * q = p + size;
5
+ char * q = p + size; // $ alloc=L4
6
6
char a = *q; // BAD
7
7
char b = *(q - 1 ); // GOOD
8
8
char c = *(q + 1 ); // BAD
@@ -14,7 +14,7 @@ void test1(int size) {
14
14
15
15
void test2 (int size) {
16
16
char * p = malloc (size);
17
- char * q = p + size - 1 ;
17
+ char * q = p + size - 1 ; // $ alloc=L16
18
18
char a = *q; // GOOD
19
19
char b = *(q - 1 ); // GOOD
20
20
char c = *(q + 1 ); // BAD
@@ -26,7 +26,7 @@ void test2(int size) {
26
26
27
27
void test3 (int size) {
28
28
char * p = malloc (size + 1 );
29
- char * q = p + (size + 1 );
29
+ char * q = p + (size + 1 ); // $ alloc=L28+1
30
30
char a = *q; // BAD
31
31
char b = *(q - 1 ); // GOOD
32
32
char c = *(q + 1 ); // BAD
@@ -38,7 +38,7 @@ void test3(int size) {
38
38
39
39
void test4 (int size) {
40
40
char * p = malloc (size - 1 );
41
- char * q = p + (size - 1 );
41
+ char * q = p + (size - 1 ); // $ alloc=L40-1
42
42
char a = *q; // BAD
43
43
char b = *(q - 1 ); // GOOD
44
44
char c = *(q + 1 ); // BAD
@@ -50,7 +50,7 @@ void test4(int size) {
50
50
51
51
char * mk_array (int size, char ** end) {
52
52
char * begin = malloc (size);
53
- *end = begin + size;
53
+ *end = begin + size; // $ alloc=L52
54
54
55
55
return begin;
56
56
}
@@ -80,7 +80,7 @@ struct array_t {
80
80
array_t mk_array (int size) {
81
81
array_t arr;
82
82
arr.begin = malloc (size);
83
- arr.end = arr.begin + size;
83
+ arr.end = arr.begin + size; // $ alloc=L82
84
84
85
85
return arr;
86
86
}
@@ -123,7 +123,7 @@ void test8(int size) {
123
123
array_t arr;
124
124
char * p = malloc (size);
125
125
arr.begin = p;
126
- arr.end = p + size;
126
+ arr.end = p + size; // $ alloc=L124
127
127
128
128
for (int i = 0 ; i < arr.end - arr.begin ; i++) {
129
129
*(arr.begin + i) = 0 ; // GOOD
@@ -141,7 +141,7 @@ void test8(int size) {
141
141
array_t *mk_array_p (int size) {
142
142
array_t *arr = (array_t *) malloc (sizeof (array_t ));
143
143
arr->begin = malloc (size);
144
- arr->end = arr->begin + size;
144
+ arr->end = arr->begin + size; // $ alloc=L143
145
145
146
146
return arr;
147
147
}
@@ -186,13 +186,13 @@ void deref_plus_one(char* q) {
186
186
187
187
void test11 (unsigned size) {
188
188
char *p = malloc (size);
189
- char *q = p + size - 1 ;
189
+ char *q = p + size - 1 ; // $ alloc=L188
190
190
deref_plus_one (q);
191
191
}
192
192
193
193
void test12 (unsigned len, unsigned index) {
194
194
char * p = (char *)malloc (len);
195
- char * end = p + len;
195
+ char * end = p + len; // $ alloc=L194
196
196
197
197
if (p + index > end) {
198
198
return ;
@@ -203,7 +203,7 @@ void test12(unsigned len, unsigned index) {
203
203
204
204
void test13 (unsigned len, unsigned index) {
205
205
char * p = (char *)malloc (len);
206
- char * end = p + len;
206
+ char * end = p + len; // $ alloc=L205
207
207
208
208
char * q = p + index;
209
209
if (q > end) {
@@ -229,14 +229,14 @@ void test15(unsigned index) {
229
229
return ;
230
230
}
231
231
int * newname = new int [size];
232
- newname[index] = 0 ; // GOOD [FALSE POSITIVE]
232
+ newname[index] = 0 ; // $ alloc=L231 // GOOD [FALSE POSITIVE]
233
233
}
234
234
235
235
void test16 (unsigned index) {
236
236
unsigned size = index + 13 ;
237
237
if (size >= index) {
238
238
int * newname = new int [size];
239
- newname[index] = 0 ; // GOOD [FALSE POSITIVE]
239
+ newname[index] = 0 ; // $ alloc=L238 // GOOD [FALSE POSITIVE]
240
240
}
241
241
}
242
242
@@ -251,14 +251,14 @@ void test17(unsigned *p, unsigned x, unsigned k) {
251
251
// The following access is okay because:
252
252
// n = 3*p[0] + k >= p[0] + k >= p[1] + k > p[1] = i
253
253
// (where p[0] denotes the original value for p[0])
254
- p[i] = x; // GOOD [FALSE POSITIVE]
254
+ p[i] = x; // $ alloc=L248 // GOOD [FALSE POSITIVE]
255
255
}
256
256
}
257
257
258
258
void test17 (unsigned len)
259
259
{
260
260
int *xs = new int [len];
261
- int *end = xs + len;
261
+ int *end = xs + len; // $ alloc=L260
262
262
for (int *x = xs; x <= end; x++)
263
263
{
264
264
int i = *x; // BAD
@@ -268,7 +268,7 @@ void test17(unsigned len)
268
268
void test18 (unsigned len)
269
269
{
270
270
int *xs = new int [len];
271
- int *end = xs + len;
271
+ int *end = xs + len; // $ alloc=L270
272
272
for (int *x = xs; x <= end; x++)
273
273
{
274
274
*x = 0 ; // BAD
@@ -278,7 +278,7 @@ void test18(unsigned len)
278
278
void test19 (unsigned len)
279
279
{
280
280
int *xs = new int [len];
281
- int *end = xs + len;
281
+ int *end = xs + len; // $ alloc=L280
282
282
for (int *x = xs; x < end; x++)
283
283
{
284
284
int i = *x; // GOOD
@@ -288,7 +288,7 @@ void test19(unsigned len)
288
288
void test20 (unsigned len)
289
289
{
290
290
int *xs = new int [len];
291
- int *end = xs + len;
291
+ int *end = xs + len; // $ alloc=L290
292
292
for (int *x = xs; x < end; x++)
293
293
{
294
294
*x = 0 ; // GOOD
@@ -305,13 +305,13 @@ void test21() {
305
305
306
306
for (int i = 0 ; i < n; i += 2 ) {
307
307
xs[i] = test21_get (i); // GOOD
308
- xs[i+1 ] = test21_get (i+1 ); // GOOD [FALSE POSITIVE]
308
+ xs[i+1 ] = test21_get (i+1 ); // $ alloc=L304 alloc=L304-1 // GOOD [FALSE POSITIVE]
309
309
}
310
310
}
311
311
312
312
void test22 (unsigned size, int val) {
313
313
char *xs = new char [size];
314
- char *end = xs + size; // GOOD
314
+ char *end = xs + size; // $ alloc=L313 // GOOD
315
315
char **current = &end;
316
316
do {
317
317
if (*current - xs < 1 ) // GOOD
@@ -323,7 +323,7 @@ void test22(unsigned size, int val) {
323
323
324
324
void test23 (unsigned size, int val) {
325
325
char *xs = new char [size];
326
- char *end = xs + size;
326
+ char *end = xs + size; // $ alloc=L325
327
327
char **current = &end;
328
328
329
329
if (val < 1 ) {
@@ -345,15 +345,15 @@ void test23(unsigned size, int val) {
345
345
346
346
void test24 (unsigned size) {
347
347
char *xs = new char [size];
348
- char *end = xs + size;
348
+ char *end = xs + size; // $ alloc=L347
349
349
if (xs < end) {
350
350
int val = *xs++; // GOOD
351
351
}
352
352
}
353
353
354
354
void test25 (unsigned size) {
355
355
char *xs = new char [size];
356
- char *end = xs + size;
356
+ char *end = xs + size; // $ alloc=L355
357
357
char *end_plus_one = end + 1 ;
358
358
int val1 = *end_plus_one; // BAD
359
359
int val2 = *(end_plus_one + 1 ); // BAD
@@ -362,7 +362,7 @@ void test25(unsigned size) {
362
362
void test26 (unsigned size) {
363
363
char *xs = new char [size];
364
364
char *p = xs;
365
- char *end = p + size;
365
+ char *end = p + size; // $ alloc=L363
366
366
367
367
if (p + 4 <= end) {
368
368
p += 4 ;
@@ -375,7 +375,7 @@ void test26(unsigned size) {
375
375
376
376
void test27 (unsigned size, bool b) {
377
377
char *xs = new char [size];
378
- char *end = xs + size;
378
+ char *end = xs + size; // $ alloc=L377
379
379
380
380
if (b) {
381
381
end++;
@@ -386,7 +386,7 @@ void test27(unsigned size, bool b) {
386
386
387
387
void test28 (unsigned size) {
388
388
char *xs = new char [size];
389
- char *end = &xs[size];
389
+ char *end = &xs[size]; // $ alloc=L388
390
390
if (xs >= end)
391
391
return ;
392
392
xs++;
@@ -397,7 +397,7 @@ void test28(unsigned size) {
397
397
398
398
void test28_simple (unsigned size) {
399
399
char *xs = new char [size];
400
- char *end = &xs[size];
400
+ char *end = &xs[size]; // $ alloc=L399
401
401
if (xs < end) {
402
402
xs++;
403
403
if (xs < end) {
@@ -408,7 +408,7 @@ void test28_simple(unsigned size) {
408
408
409
409
void test28_simple2 (unsigned size) {
410
410
char *xs = new char [size];
411
- char *end = &xs[size];
411
+ char *end = &xs[size]; // $ alloc=L410
412
412
if (xs < end) {
413
413
xs++;
414
414
if (xs < end + 1 ) {
@@ -419,7 +419,7 @@ void test28_simple2(unsigned size) {
419
419
420
420
void test28_simple3 (unsigned size) {
421
421
char *xs = new char [size];
422
- char *end = &xs[size];
422
+ char *end = &xs[size]; // $ alloc=L421
423
423
if (xs < end) {
424
424
xs++;
425
425
if (xs - 1 < end) {
@@ -430,7 +430,7 @@ void test28_simple3(unsigned size) {
430
430
431
431
void test28_simple4 (unsigned size) {
432
432
char *xs = new char [size];
433
- char *end = &xs[size];
433
+ char *end = &xs[size]; // $ alloc=L432
434
434
if (xs < end) {
435
435
end++;
436
436
xs++;
@@ -442,7 +442,7 @@ void test28_simple4(unsigned size) {
442
442
443
443
void test28_simple5 (unsigned size) {
444
444
char *xs = new char [size];
445
- char *end = &xs[size];
445
+ char *end = &xs[size]; // $ alloc=L444
446
446
end++;
447
447
if (xs < end) {
448
448
xs++;
@@ -466,7 +466,7 @@ void test28_simple6(unsigned size) {
466
466
467
467
void test28_simple7 (unsigned size) {
468
468
char *xs = new char [size];
469
- char *end = &xs[size];
469
+ char *end = &xs[size]; // $ alloc=L468
470
470
end++;
471
471
if (xs < end) {
472
472
xs++;
@@ -478,7 +478,7 @@ void test28_simple7(unsigned size) {
478
478
479
479
void test28_simple8 (unsigned size) {
480
480
char *xs = new char [size];
481
- char *end = &xs[size];
481
+ char *end = &xs[size]; // $ alloc=L480
482
482
end += 500 ;
483
483
if (xs < end) {
484
484
xs++;
@@ -545,7 +545,7 @@ void test31_simple2(unsigned size, unsigned src_pos)
545
545
src_pos = size;
546
546
}
547
547
if (src_pos < size + 1 ) {
548
- xs[src_pos] = 0 ; // BAD
548
+ xs[src_pos] = 0 ; // $ alloc=L543 // BAD
549
549
}
550
550
}
551
551
@@ -556,7 +556,7 @@ void test31_simple3(unsigned size, unsigned src_pos)
556
556
src_pos = size;
557
557
}
558
558
if (src_pos - 1 < size) {
559
- xs[src_pos] = 0 ; // BAD
559
+ xs[src_pos] = 0 ; // $ alloc=L554 // BAD
560
560
}
561
561
}
562
562
@@ -644,13 +644,13 @@ void test31_simple1_sub1(unsigned size, unsigned src_pos)
644
644
src_pos = size;
645
645
}
646
646
if (src_pos < size) {
647
- xs[src_pos] = 0 ; // BAD
647
+ xs[src_pos] = 0 ; // $ alloc=L642-1 // BAD
648
648
}
649
649
}
650
650
651
651
void test32 (unsigned size) {
652
652
char *xs = new char [size];
653
- char *end = &xs[size];
653
+ char *end = &xs[size]; // $ alloc=L652
654
654
if (xs >= end)
655
655
return ;
656
656
xs++;
@@ -672,12 +672,12 @@ void test33(unsigned size, unsigned src_pos)
672
672
while (dst_pos < size - 1 ) {
673
673
dst_pos++;
674
674
if (true )
675
- xs[dst_pos++] = 0 ; // GOOD [FALSE POSITIVE]
675
+ xs[dst_pos++] = 0 ; // $ alloc=L667+1 // GOOD [FALSE POSITIVE]
676
676
}
677
677
}
678
678
679
679
int * pointer_arithmetic (int *p, int offset) {
680
- return p + offset;
680
+ return p + offset; // $ alloc=L684
681
681
}
682
682
683
683
void test_missing_call_context_1 (unsigned size) {
0 commit comments