declare code as C99 compliant, include stdbool.h unconditionally#1723
Conversation
|
Explicitly setting the C standard is fine but we shouldn't change the includes or boolean type. |
Third, Chocolate Doom doesn't even start if we keep |
|
What do you mean by "doesn't even start"? Crashes right away? Including |
It fails with That's here, I guess the first boolean check it approaches at run-time: #1 0x00005555555ab72e in R_InstallSpriteLump (lump=<optimized out>, frame=<optimized out>, rotation=<optimized out>, flipped=flipped@entry=false) at r_things.c:137
137 I_Error ("R_InitSprites: Sprite %s frame %c has rotations "
(gdb) l
132 return;
133 }
134
135 // the lump is only used for one rotation
136 if (sprtemp[frame].rotate == false)
137 I_Error ("R_InitSprites: Sprite %s frame %c has rotations "
138 "and a rot=0 lump", spritename, 'A'+frame);
139
140 sprtemp[frame].rotate = true;
141
Well, that doesn't make it any better, or does it? |
|
Ok, so this was fun. After playing around with Godbolt, it seems to me that when performing checks against
This might seem a bit strange at first, but the C standard says that a Now, if you look at the code inside memset (sprtemp,-1, sizeof(sprtemp));The variable
|
|
Thank you for the analysis! The problem with Doom code is that it assumes anything non- |
|
Well yeah, the |
|
See, and this is why I insist on |
|
Ah, the joys of undefined behavior. Nasal demons can't be killed with a shotgun. Please add a comment to the boolean typedef to explain why it must be int. With C99 we have to be slightly careful since the coding style calls for all variable declarations at the beginning of a block. @fragglet Do you have an opinion on this? If not, I'll approve this PR after the comment is added. |
|
Late reply, but I'm very much in favour of this change. C99 is >25 years old now, we shouldn't be wedded to ANSI C forever. Plus the It would be great to see the |
|
I added a draft PR for ubsan workflow #1724 It fails as expected but the ubsan output is lost. Is there an easy way to make quickcheck preserve that? After that we just need someone to go and fix all the problems... |
Fixes #1722