Skip to content

Commit

Permalink
Add sample cpp code for CodeQL to flag
Browse files Browse the repository at this point in the history
  • Loading branch information
samjwu committed May 1, 2024
1 parent caa88ed commit db94402
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions testcpp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
struct {
int s : 4; //wrong: behavior of bit-field members with implicit signage vary across compilers
unsigned int : 24; //correct: explicitly unsigned
signed int : 4; //correct: explicitly signed
} bits;

//Function foo's array parameter has a specified size
void foo(int a[10]) {
int i = 0;
for (i = 0; i <10; i++) {
a[i] = i * 2;
}
}

int my_arr[5];
foo(my_arr); //my_arr is smaller than foo's array parameter, and will cause access to memory outside its bounds

0 comments on commit db94402

Please sign in to comment.