foralex / picoc

Automatically exported from code.google.com/p/picoc
0 stars 0 forks source link

printf causes seg fault #157

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
int a;
printf(a);

What is the expected output? What do you see instead?
segmentation fault

What version of the product are you using? On what operating system?
rev572

Original issue reported on code.google.com by carlojpi...@gmail.com on 27 May 2012 at 12:07

GoogleCodeExporter commented 8 years ago
I am not sure this is a bug. The first argument of printf is a pointer. If an 
int is passed, what do you expect?

Original comment by christop...@gmail.com on 28 Aug 2012 at 8:40

GoogleCodeExporter commented 8 years ago
well, i expect the picoC says me exactly what you are telling me
instead of do segmentation fault and bad stuff

Original comment by carlojpi...@gmail.com on 28 Aug 2012 at 11:39

GoogleCodeExporter commented 8 years ago
You are right. Surprisingly, printf(0); segfaults while printf(1); returns the 
error message "can't set char* from char in argument 1 of call to printf()".
In your example, since a is not explicitely initialised, it is set to 0.

Original comment by christop...@gmail.com on 29 Aug 2012 at 2:26

GoogleCodeExporter commented 8 years ago
Thanks for the analysis guys.

I've added a check for a null format pointer to printf() and friends.

Strangely enough, printf(0) is semantically valid (but will cause a crash) 
because 0 is the same as a null pointer. printf(1) can be detected as having an 
invalid data type because it requires passing the integer to a char * argument.

This is what you see now:

picoc> printf(0);
[null format]

Original comment by zik.sale...@gmail.com on 30 Aug 2012 at 10:19