Skip to content

Commit 51f8b53

Browse files
authored
added test to make sure samples produce the expected output / adjusted samples output and small cleanup (#6180)
1 parent aa122ea commit 51f8b53

File tree

20 files changed

+110
-59
lines changed

20 files changed

+110
-59
lines changed

samples/arrayIndexOutOfBounds/out.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
samples\arrayIndexOutOfBounds_1\bad.c:7:6: error: Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]
2+
a[2] = 0;
3+
^

samples/arrayIndexOutOfBounds_2/bad.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
int main()
2+
{
3+
int a[2];
4+
int i;
5+
for (i = 0; i < 3; i++)
6+
a[i] = 0;
7+
return a[0];
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
int main()
2+
{
3+
int a[3];
4+
int i;
5+
for (i = 0; i < 3; i++)
6+
a[i] = 0;
7+
return a[0];
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
samples\arrayIndexOutOfBounds_2\bad.c:6:10: error: Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]
2+
a[i] = 0;
3+
^
4+
samples\arrayIndexOutOfBounds_2\bad.c:5:19: note: Assuming that condition 'i<3' is not redundant
5+
for (i = 0; i < 3; i++)
6+
^
7+
samples\arrayIndexOutOfBounds_2\bad.c:6:10: note: Array index out of bounds
8+
a[i] = 0;
9+
^

samples/bufferAccessOutOfBounds/bad.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
#include <stdio.h>
12
int main()
23
{
3-
int a[2];
4-
int i;
5-
for (i = 0; i < 3; i++)
6-
a[i] = 0;
7-
return a[0];
4+
char str[5];
5+
strcpy(str, "0123456789abcdef");
6+
return 0;
87
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
#include <stdio.h>
12
int main()
23
{
3-
int a[3];
4-
int i;
5-
for (i = 0; i < 3; i++)
6-
a[i] = 0;
7-
return a[0];
4+
char str[10];
5+
snprintf(str, 10, "%s", "abc");
6+
return 0;
87
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
samples\bufferAccessOutOfBounds\bad.c:6:10: error: Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]
2-
a[i] = 0;
3-
^
1+
samples\bufferAccessOutOfBounds\bad.c:5:12: error: Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]
2+
strcpy(str, "0123456789abcdef");
3+
^

0 commit comments

Comments
 (0)