<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[&quot;Fun bug of the month, mesa edition, episode may&quot;]]></title><description><![CDATA[<p>"Fun bug of the month, mesa edition, episode may"</p><p>so if you do "uint64_t some_var = 1 &lt;&lt; 31;" in C you get "0xffffffff80000000" as the value, because that's super obvious and not confusing at all.</p><p>It's pretty funny getting reminded how non-intuitive and broken C is from time to time.</p>]]></description><link>https://board.circlewithadot.net/topic/611a7208-9161-4cc8-bbe0-c8c0b62271c4/fun-bug-of-the-month-mesa-edition-episode-may</link><generator>RSS for Node</generator><lastBuildDate>Sat, 30 May 2026 22:57:32 GMT</lastBuildDate><atom:link href="https://board.circlewithadot.net/topic/611a7208-9161-4cc8-bbe0-c8c0b62271c4.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 17 May 2026 20:32:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Tue, 19 May 2026 11:50:56 GMT]]></title><description><![CDATA[<p><span><a href="/user/karolherbst%40chaos.social">@<span>karolherbst</span></a></span> ohhh, footgun i didn't know about yet!</p>]]></description><link>https://board.circlewithadot.net/post/https://mastodon.gamedev.place/users/eniko/statuses/116601091276974348</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://mastodon.gamedev.place/users/eniko/statuses/116601091276974348</guid><dc:creator><![CDATA[eniko@mastodon.gamedev.place]]></dc:creator><pubDate>Tue, 19 May 2026 11:50:56 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Tue, 19 May 2026 10:28:26 GMT]]></title><description><![CDATA[<p><span><a href="https://chaos.social/@trilader">@<span>trilader</span></a></span> <span><a href="/user/karolherbst%40chaos.social">@<span>karolherbst</span></a></span> 1L &lt;&lt; alone would do the trick on real world 64-bit machines, but i think compiler is still fully allowed to do the wrong thing. msvc perhaps still has 32-bit longs on 64-bit platforms?</p><p>i think you need to make sure it's unsigned so that sign extension has no chance of occurring, so my money is on 1U &lt;&lt; 31?</p>]]></description><link>https://board.circlewithadot.net/post/https://metalhead.club/users/lkundrak/statuses/116600766873425076</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://metalhead.club/users/lkundrak/statuses/116600766873425076</guid><dc:creator><![CDATA[lkundrak@metalhead.club]]></dc:creator><pubDate>Tue, 19 May 2026 10:28:26 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Tue, 19 May 2026 10:21:14 GMT]]></title><description><![CDATA[<p><span><a href="/user/karolherbst%40chaos.social">@<span>karolherbst</span></a></span> taking off my "understands sign extension" badge</p><p>wore it with pride, but the pride was misplaced</p>]]></description><link>https://board.circlewithadot.net/post/https://metalhead.club/users/lkundrak/statuses/116600738549516422</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://metalhead.club/users/lkundrak/statuses/116600738549516422</guid><dc:creator><![CDATA[lkundrak@metalhead.club]]></dc:creator><pubDate>Tue, 19 May 2026 10:21:14 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Tue, 19 May 2026 06:41:46 GMT]]></title><description><![CDATA[<span><a href="/user/karolherbst%40chaos.social" rel="ugc">@<span>karolherbst</span></a></span> <span><a href="/user/trilader%40chaos.social" rel="ugc">@<span>trilader</span></a></span> Yeah, travelling to 1972 and changing the language would be best :-).]]></description><link>https://board.circlewithadot.net/post/https://social.kernel.org/objects/c183d112-f2f7-49b5-8819-114416f5039b</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://social.kernel.org/objects/c183d112-f2f7-49b5-8819-114416f5039b</guid><dc:creator><![CDATA[pavel@social.kernel.org]]></dc:creator><pubDate>Tue, 19 May 2026 06:41:46 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Tue, 19 May 2026 05:24:12 GMT]]></title><description><![CDATA[<p><span><a href="/user/karolherbst%40chaos.social">@<span>karolherbst</span></a></span> I recently read <a href="https://www.os2museum.com/wp/bitfield-pitfalls/" rel="nofollow noopener"><span>https://www.</span><span>os2museum.com/wp/bitfield-pitf</span><span>alls/</span></a> which is a similar pitfall?</p>]]></description><link>https://board.circlewithadot.net/post/https://mastodon.social/users/Lalufu/statuses/116599570569505045</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://mastodon.social/users/Lalufu/statuses/116599570569505045</guid><dc:creator><![CDATA[lalufu@mastodon.social]]></dc:creator><pubDate>Tue, 19 May 2026 05:24:12 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Mon, 18 May 2026 22:46:25 GMT]]></title><description><![CDATA[<p><span><a href="/user/karolherbst%40chaos.social">@<span>karolherbst</span></a></span> <span><a href="/user/david_chisnall%40infosec.exchange">@<span>david_chisnall</span></a></span> <span><a href="/user/jann%40infosec.exchange">@<span>jann</span></a></span> That particular change would break a lot!</p>]]></description><link>https://board.circlewithadot.net/post/https://framapiaf.org/users/blp/statuses/116598006447775805</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://framapiaf.org/users/blp/statuses/116598006447775805</guid><dc:creator><![CDATA[blp@framapiaf.org]]></dc:creator><pubDate>Mon, 18 May 2026 22:46:25 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Mon, 18 May 2026 22:43:51 GMT]]></title><description><![CDATA[<p><span><a href="/user/pavel%40social.kernel.org">@<span>pavel</span></a></span> <span><a href="https://chaos.social/@trilader">@<span>trilader</span></a></span> the actual right solution would be to fix the language <img src="https://board.circlewithadot.net/assets/plugins/nodebb-plugin-emoji/emoji/android/1f61b.png?v=28325c671da" class="not-responsive emoji emoji-android emoji--stuck_out_tongue" style="height:23px;width:auto;vertical-align:middle" title=":P" alt="😛" /></p>]]></description><link>https://board.circlewithadot.net/post/https://chaos.social/users/karolherbst/statuses/116597996366906205</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://chaos.social/users/karolherbst/statuses/116597996366906205</guid><dc:creator><![CDATA[karolherbst@chaos.social]]></dc:creator><pubDate>Mon, 18 May 2026 22:43:51 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Mon, 18 May 2026 22:42:33 GMT]]></title><description><![CDATA[<p><span><a href="/user/david_chisnall%40infosec.exchange">@<span>david_chisnall</span></a></span> <span><a href="/user/jann%40infosec.exchange">@<span>jann</span></a></span> at least C23 fixes one part of this by requiring two's complement for integers.</p><p>But also, I just wished C would mandate that constants are just assumed to be of the "expected" type, because in 99.999999% of all cases a programmer really meant the obvious thing with "uint64_t x = 1 &lt;&lt; 31".</p><p>But I guess we'll just keep those horrible semantics C has in a couple of areas, because nobody want to fix those things, because "it could break things".</p>]]></description><link>https://board.circlewithadot.net/post/https://chaos.social/users/karolherbst/statuses/116597991259995523</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://chaos.social/users/karolherbst/statuses/116597991259995523</guid><dc:creator><![CDATA[karolherbst@chaos.social]]></dc:creator><pubDate>Mon, 18 May 2026 22:42:33 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Mon, 18 May 2026 22:40:48 GMT]]></title><description><![CDATA[<span><a href="/user/trilader%40chaos.social" rel="ugc">@<span>trilader</span></a></span> <span><a href="/user/karolherbst%40chaos.social" rel="ugc">@<span>karolherbst</span></a></span> Actually right solution would be uint64_t some_var = ((uint 64_t)1) &lt;&lt; 31; AFAICT.]]></description><link>https://board.circlewithadot.net/post/https://social.kernel.org/objects/0b709ba2-12ff-43db-8a14-9d5e995be040</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://social.kernel.org/objects/0b709ba2-12ff-43db-8a14-9d5e995be040</guid><dc:creator><![CDATA[pavel@social.kernel.org]]></dc:creator><pubDate>Mon, 18 May 2026 22:40:48 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Mon, 18 May 2026 22:34:52 GMT]]></title><description><![CDATA[<span><a href="/user/trilader%40chaos.social" rel="ugc">@<span>trilader</span></a></span> <span><a href="/user/karolherbst%40chaos.social" rel="ugc">@<span>karolherbst</span></a></span> Yes, int promotion. 1L&lt;&lt;31L would still be broken on 32-bit architectures (as long is 32 bit there). You'd need 1LL or something, AFAICT.]]></description><link>https://board.circlewithadot.net/post/https://social.kernel.org/objects/d9466b50-b91a-4f93-92fd-54105a9bc45b</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://social.kernel.org/objects/d9466b50-b91a-4f93-92fd-54105a9bc45b</guid><dc:creator><![CDATA[pavel@social.kernel.org]]></dc:creator><pubDate>Mon, 18 May 2026 22:34:52 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Mon, 18 May 2026 22:18:46 GMT]]></title><description><![CDATA[<span><a href="/user/karolherbst%40chaos.social" rel="ugc">@<span>karolherbst</span></a></span> C is 1973 or so. If you believe it is confusing, try assembly :-).]]></description><link>https://board.circlewithadot.net/post/https://social.kernel.org/objects/aa2afb3e-9c41-4955-95f1-d3990b19b4ba</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://social.kernel.org/objects/aa2afb3e-9c41-4955-95f1-d3990b19b4ba</guid><dc:creator><![CDATA[pavel@social.kernel.org]]></dc:creator><pubDate>Mon, 18 May 2026 22:18:46 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Mon, 18 May 2026 21:05:47 GMT]]></title><description><![CDATA[<p><span><a href="/user/ewhac%40mastodon.social">@<span>ewhac</span></a></span> <span><a href="/user/karolherbst%40chaos.social">@<span>karolherbst</span></a></span> Yes. In the other thread leg of the original post I also posted about that clang even warns you about the behavior of 1 &lt;&lt; 31 without U or L suffix, provided you enable the right, off by default, warning that GCC doesn't have. Another leg notes that GCC catches this at runtime with ubsan enabled.</p>]]></description><link>https://board.circlewithadot.net/post/https://chaos.social/users/trilader/statuses/116597610713096037</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://chaos.social/users/trilader/statuses/116597610713096037</guid><dc:creator><![CDATA[trilader@chaos.social]]></dc:creator><pubDate>Mon, 18 May 2026 21:05:47 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Mon, 18 May 2026 20:26:38 GMT]]></title><description><![CDATA[<p><span><a href="https://chaos.social/@trilader">@<span>trilader</span></a></span> <span><a href="/user/karolherbst%40chaos.social">@<span>karolherbst</span></a></span> "Um, actually..."</p><p>I believe it would work as expected with:</p><p>1U &lt;&lt; 31;</p><p>The unexpected part is that sign extension from 32 to 64 bits takes place before reinterpretation to unsigned.  The C99 standard is admittedly opaque on this point.  If you make the rvalue unsigned as well, then you get the (presumably) expected result.</p><p>(Just tested it with GCC 13.3 -- it works.)</p>]]></description><link>https://board.circlewithadot.net/post/https://mastodon.social/users/ewhac/statuses/116597456814549281</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://mastodon.social/users/ewhac/statuses/116597456814549281</guid><dc:creator><![CDATA[ewhac@mastodon.social]]></dc:creator><pubDate>Mon, 18 May 2026 20:26:38 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Mon, 18 May 2026 19:26:34 GMT]]></title><description><![CDATA[<p><span><a href="/user/karolherbst%40chaos.social" rel="nofollow noopener">@<span>karolherbst</span></a></span> <span><a href="/user/jann%40infosec.exchange">@<span>jann</span></a></span> </p><p>It’s UB in the general case because, if the operand is not a constant, you want to lower it to a shift instruction but C works with targets that have different number representations. Ones or twos complements, or explicit sign bits are all permitted, but all of these will give different behaviours if you flip the top bit.</p><p>For wider shifts, different ISAs had different semantics for shifts wider than the register, so C made that fully undefined. </p><p>This combination lets you lower source-level shifts to a shift instruction. </p><p>C also doesn’t mandate that this be constant evaluated unless the result is used as a constant, so there’s no way to force implementations to diagnose the UB at compile time for this case. But, as a QoI issue, it is permitted and compilers should.</p>]]></description><link>https://board.circlewithadot.net/post/https://infosec.exchange/users/david_chisnall/statuses/116597220589798192</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://infosec.exchange/users/david_chisnall/statuses/116597220589798192</guid><dc:creator><![CDATA[david_chisnall@infosec.exchange]]></dc:creator><pubDate>Mon, 18 May 2026 19:26:34 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Mon, 18 May 2026 19:18:19 GMT]]></title><description><![CDATA[<p><span><a href="https://ieji.de/@puppethead">@<span>puppethead</span></a></span> <span><a href="/user/karolherbst%40chaos.social">@<span>karolherbst</span></a></span> When not using the U (or L) suffix 1&lt;&lt;31 triggers clang's -Wshift-sign-overflow warning. However that warning is not enabled by default and gcc doesn't support it at all.</p>]]></description><link>https://board.circlewithadot.net/post/https://chaos.social/users/trilader/statuses/116597188156389254</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://chaos.social/users/trilader/statuses/116597188156389254</guid><dc:creator><![CDATA[trilader@chaos.social]]></dc:creator><pubDate>Mon, 18 May 2026 19:18:19 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Mon, 18 May 2026 00:16:33 GMT]]></title><description><![CDATA[<p><span><a href="/user/jann%40infosec.exchange">@<span>jann</span></a></span> ohh it's totally the languages fault even if it wouldn't be UB, because that's just the worst way to specify this.</p><p>Like it's just a design bug really. And no matter how much this is UB or not won't change that.</p>]]></description><link>https://board.circlewithadot.net/post/https://chaos.social/users/karolherbst/statuses/116592698537664035</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://chaos.social/users/karolherbst/statuses/116592698537664035</guid><dc:creator><![CDATA[karolherbst@chaos.social]]></dc:creator><pubDate>Mon, 18 May 2026 00:16:33 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Mon, 18 May 2026 00:13:55 GMT]]></title><description><![CDATA[<p><span><a href="/user/jann%40infosec.exchange">@<span>jann</span></a></span> <span><a href="/user/karolherbst%40chaos.social">@<span>karolherbst</span></a></span> </p><p>It was not UB in C90. That is why it was UB without ubsan ...</p>]]></description><link>https://board.circlewithadot.net/post/https://hachyderm.io/users/pinskia/statuses/116592688169795540</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://hachyderm.io/users/pinskia/statuses/116592688169795540</guid><dc:creator><![CDATA[pinskia@hachyderm.io]]></dc:creator><pubDate>Mon, 18 May 2026 00:13:55 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Mon, 18 May 2026 00:13:39 GMT]]></title><description><![CDATA[<p><span><a href="/user/karolherbst%40chaos.social" rel="nofollow noopener">@<span>karolherbst</span></a></span> yeah, I guess my point is that, for the code you showed, a C compiler would be well within its rights to refuse to build that code or complain about it, so this is not entirely the language's fault</p>]]></description><link>https://board.circlewithadot.net/post/https://infosec.exchange/users/jann/statuses/116592687149063225</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://infosec.exchange/users/jann/statuses/116592687149063225</guid><dc:creator><![CDATA[jann@infosec.exchange]]></dc:creator><pubDate>Mon, 18 May 2026 00:13:39 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Sun, 17 May 2026 23:58:23 GMT]]></title><description><![CDATA[<p><span><a href="/user/jann%40infosec.exchange">@<span>jann</span></a></span> yeah technically it's UB, but there is only so much you can optimize with a 1-2 instruction pattern that it doesn't really matter in practice, because most impls will do the same (more or less).</p><p>Like there is UB and then there is UB.</p>]]></description><link>https://board.circlewithadot.net/post/https://chaos.social/users/karolherbst/statuses/116592627136253580</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://chaos.social/users/karolherbst/statuses/116592627136253580</guid><dc:creator><![CDATA[karolherbst@chaos.social]]></dc:creator><pubDate>Sun, 17 May 2026 23:58:23 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Sun, 17 May 2026 23:09:07 GMT]]></title><description><![CDATA[<p><span><a href="/user/karolherbst%40chaos.social" rel="nofollow noopener">@<span>karolherbst</span></a></span> but apparently gcc has decided to not treat it as UB, except when using UBSAN: <a href="https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html" rel="nofollow noopener"><span>https://</span><span>gcc.gnu.org/onlinedocs/gcc/Int</span><span>egers-implementation.html</span></a></p>]]></description><link>https://board.circlewithadot.net/post/https://infosec.exchange/users/jann/statuses/116592433380424278</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://infosec.exchange/users/jann/statuses/116592433380424278</guid><dc:creator><![CDATA[jann@infosec.exchange]]></dc:creator><pubDate>Sun, 17 May 2026 23:09:07 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Sun, 17 May 2026 23:04:59 GMT]]></title><description><![CDATA[<p><span><a href="/user/karolherbst%40chaos.social" rel="nofollow noopener">@<span>karolherbst</span></a></span> I think that's UB? see C99 6.5.7 "Bitwise shift operators" - the LHS is signed and the result of the computation is not representable in the result type</p>]]></description><link>https://board.circlewithadot.net/post/https://infosec.exchange/users/jann/statuses/116592417125759430</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://infosec.exchange/users/jann/statuses/116592417125759430</guid><dc:creator><![CDATA[jann@infosec.exchange]]></dc:creator><pubDate>Sun, 17 May 2026 23:04:59 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Sun, 17 May 2026 20:38:15 GMT]]></title><description><![CDATA[<p><span><a href="/user/karolherbst%40chaos.social">@<span>karolherbst</span></a></span> Yeah. Things like this make me think someone needs to invent -fbackwards-compatible-bs=off</p>]]></description><link>https://board.circlewithadot.net/post/https://chaos.social/users/trilader/statuses/116591840174103742</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://chaos.social/users/trilader/statuses/116591840174103742</guid><dc:creator><![CDATA[trilader@chaos.social]]></dc:creator><pubDate>Sun, 17 May 2026 20:38:15 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Sun, 17 May 2026 20:36:42 GMT]]></title><description><![CDATA[<p><span><a href="https://chaos.social/@trilader">@<span>trilader</span></a></span> yeah sure, but any competent and modern language would type the constant to what's expected, not make it int32 by default, because that's just broken imho.</p><p>Like any new language doing that today would be considered broken on arrival.</p>]]></description><link>https://board.circlewithadot.net/post/https://chaos.social/users/karolherbst/statuses/116591834041534192</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://chaos.social/users/karolherbst/statuses/116591834041534192</guid><dc:creator><![CDATA[karolherbst@chaos.social]]></dc:creator><pubDate>Sun, 17 May 2026 20:36:42 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Fun bug of the month, mesa edition, episode may&quot; on Sun, 17 May 2026 20:35:17 GMT]]></title><description><![CDATA[<p><span><a href="/user/karolherbst%40chaos.social">@<span>karolherbst</span></a></span> For my understanding: That's default int promotion + sign extend on 64 bit extension? Would 1L &lt;&lt; 31L fix this or is there other pitfalls with that?</p>]]></description><link>https://board.circlewithadot.net/post/https://chaos.social/users/trilader/statuses/116591828484017334</link><guid isPermaLink="true">https://board.circlewithadot.net/post/https://chaos.social/users/trilader/statuses/116591828484017334</guid><dc:creator><![CDATA[trilader@chaos.social]]></dc:creator><pubDate>Sun, 17 May 2026 20:35:17 GMT</pubDate></item></channel></rss>