-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1139 from mrstanb/detect-deallocation-at-offset
Detect memory deallocation at offset from memory start
- Loading branch information
Showing
5 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <stdlib.h> | ||
|
||
int main(int argc, char const *argv[]) { | ||
char *ptr = malloc(42 * sizeof(char)); | ||
ptr = ptr + 7; | ||
free(ptr); //WARN | ||
|
||
return 0; | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/regression/75-invalid_dealloc/06-realloc-at-offset.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <stdlib.h> | ||
|
||
#define MAX_SIZE 5000 | ||
|
||
int main(int argc, char const *argv[]) { | ||
char *ptr = malloc(42 * sizeof(char)); | ||
ptr = ptr + 7; | ||
realloc(ptr, MAX_SIZE); //WARN | ||
|
||
return 0; | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/regression/75-invalid_dealloc/07-free-at-struct-offset.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <stdlib.h> | ||
|
||
typedef struct custom_t { | ||
char *x; | ||
int y; | ||
} custom_t; | ||
|
||
int main(int argc, char const *argv[]) { | ||
custom_t *struct_ptr = malloc(sizeof(custom_t)); | ||
struct_ptr->x = malloc(10 * sizeof(char)); | ||
free(&struct_ptr->x); //NOWARN | ||
free(&struct_ptr->y); //WARN | ||
free(struct_ptr); //NOWARN | ||
return 0; | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/regression/75-invalid_dealloc/08-realloc-at-struct-offset.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <stdlib.h> | ||
|
||
typedef struct custom_t { | ||
char *x; | ||
int y; | ||
} custom_t; | ||
|
||
int main(int argc, char const *argv[]) { | ||
custom_t *struct_ptr = malloc(sizeof(custom_t)); | ||
struct_ptr->x = malloc(10 * sizeof(char)); | ||
realloc(&struct_ptr->x, 50); //NOWARN | ||
realloc(&struct_ptr->y, 50); //WARN | ||
realloc(struct_ptr, 2 * sizeof(custom_t)); //NOWARN | ||
return 0; | ||
} |