Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all bugs #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions c-src/point.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,45 @@ void print_point(struct POINT *pnt)
get_x(pnt), get_y(pnt));
}

int resource_leak()
{
FILE *fp=fopen("c:\\some\file", "r");

if (fp == NULL) {
return 1;
}

return 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RESOURCE_LEAK: resource of type _IO_FILE acquired to return by call to fopen() at line 37, column 14 is not released after line 43, column 5.

}

int memory_leak()
{
struct POINT *p = malloc(sizeof(struct POINT));

if (p == NULL) {
return (-2);
}

return -1;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEMORY_LEAK: memory dynamically allocated to return by call to malloc() at line 48, column 23 is not reachable after line 54, column 5.

}

void dead_store(struct POINT *pnt)
{
int new_x = 9;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEAD_STORE: The value written to &new_x (type int) is never used.

new_x = get_y(pnt);
set_x(pnt, new_x);
}

int null_dereference()
{
struct POINT *p = malloc(sizeof(struct POINT));

get_x(p);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NULL_DEREFERENCE: pointer p last assigned on line 66 could be null and is dereferenced by call to get_x() at line 68, column 5.

free(p);

return 0;
}

int main(void)
{
struct POINT *pnt = malloc(sizeof(struct POINT));
Expand Down