Skip to content

Binary add segfaults when at least 1 arg is non-numeric, and both are non-pointer types#42

Open
StrongerXi wants to merge 1 commit intorui314:mainfrom
StrongerXi:segfault-in-binary-add
Open

Binary add segfaults when at least 1 arg is non-numeric, and both are non-pointer types#42
StrongerXi wants to merge 1 commit intorui314:mainfrom
StrongerXi:segfault-in-binary-add

Conversation

@StrongerXi
Copy link
Copy Markdown

Problem

The following program segfaults in new_add function from parse.c

void foo() { }

void bar() {
  1 + foo();
}

Proposal

Check for the case when both args are non-pointer types; check NULL explicitly to improve readability.

Note the following program still compiles with or without this patch:

void foo() { }

void bar() {
  int *a;
  a + foo();
}

It could be fixed easily, but like mentioned in #41, a separate "typecheck" phase would probably be a better solution IMHO.

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

Successfully merging this pull request may close these issues.

1 participant