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

[C2M] Wrong initialization of struct's string fields #18

Closed
edubart opened this issue Dec 7, 2019 · 3 comments
Closed

[C2M] Wrong initialization of struct's string fields #18

edubart opened this issue Dec 7, 2019 · 3 comments

Comments

@edubart
Copy link
Contributor

edubart commented Dec 7, 2019

The following:

#include <stdio.h>
struct Boo { char data[5]; };
struct Boo boo = {"test"};
int main(int argc, char **argv) {
  puts(boo.data);
  return 0;
}

Outputs:

tests/bug1.c:3:19: warning -- assigning pointer without cast to integer
����U

It is expected as in GCC/Clang to print test, but it prints random data, because looks like it's wrongly assigning a pointer instead of initializing the struct.

PS: I was trying this project, mainly because I'm working in other language that already compiles to C, and I found this project promising as it's minimal and can compile C very fast. During my tests I found this issue.

@vnmakarov
Copy link
Owner

Thank you for reporting this. I reproduced the problem. It looks c2m is trying to assign pointer to the string to the first element of the data. That is why this warning.

I'll work on it and probably the fix will be available on the next week. Unfortunately, C2M code for initialization in C is very complicated despite I already rewrote the code once.

@vnmakarov
Copy link
Owner

I've just fixed it. The fix is in the repository.

@edubart
Copy link
Contributor Author

edubart commented Dec 8, 2019

Thanks, it works!

@edubart edubart closed this as completed Dec 8, 2019
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