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

[P1] Segmentation fault on -fanalyzer #146

Closed
iphydf opened this issue Mar 5, 2024 · 7 comments
Closed

[P1] Segmentation fault on -fanalyzer #146

iphydf opened this issue Mar 5, 2024 · 7 comments

Comments

@iphydf
Copy link

iphydf commented Mar 5, 2024

crash.c:

struct a {
  char b;
} c;
void d() {
  struct a e = c;
}

Invocation: cake -fanalyzer crash.c

Segfault happens here:

set_object_state(ctx,

#22 0.968 Program received signal SIGSEGV, Segmentation fault.
#22 0.968 0x000000000041cd2e in set_object_state (ctx=ctx@entry=0x7fffb7a76810, p_type=p_type@entry=0x7fd0819df190, p_object=p_object@entry=0x7fd0819df158, p_source_type=p_source_type@entry=0x7fffb7a76110, p_object_source=p_object_source@entry=0x7fd0819d9a88, error_position=error_position@entry=0x7fd0819f62f0) at object.c:633
#22 0.968 633	                                set_object_state(ctx,
@iphydf
Copy link
Author

iphydf commented Mar 5, 2024

Another segfault, I didn't check if it's the same root cause:

#include <ownership.h>

typedef struct Foo {
    int *owner p;
} Foo;

Foo *owner foo_new(void) {
    Foo *owner foo = (Foo *owner)calloc(1, sizeof(Foo));

    if (foo == NULL) {
        return NULL;
    }

    return foo;
}

@thradams
Copy link
Owner

thradams commented Mar 5, 2024

The static variables state were not begin tracked.

struct a {
  char b;
} c;
void d() {
  struct a e = c;
}

here is the plan...
initialize the global variables at declaration. if it is const the state if fixed in all the program.
if the it is not const, each time we enter in a function the state will be "unknown" at the begging of the function.
not sure how to implement. maybe at first usage inside the function make it "unknown" then i put in a list "already used".

@iphydf
Copy link
Author

iphydf commented Mar 5, 2024

Cool, then the second one is a separate bug.

@thradams
Copy link
Owner

thradams commented Mar 5, 2024

this sample also needs attention

void d() {
  static struct a {  char b;} c;
  struct a e = c;
}

@iphydf iphydf changed the title Segmentation fault on -fanalyzer [P1] Segmentation fault on -fanalyzer Mar 5, 2024
@thradams
Copy link
Owner

thradams commented Mar 5, 2024

I fixed the segmentation fault,
but the state of global variables still wrong. I need to reset the state of global variables.

@thradams
Copy link
Owner

thradams commented Mar 6, 2024

created
global variables with -fanalyzer #150

@thradams
Copy link
Owner

thradams commented Mar 6, 2024

segmentation fault fixed

@thradams thradams closed this as completed Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants