Predicted "undefined behaviour"
Monday, April 4, 2011 7:15:39 AM
In programming at least a bug report is posted, and here's one that caused some rattle (note that even Linus Torvalds wrote a few comments there): https://bugzilla.redhat.com/show_bug.cgi?id=638477
Briefly, the problem started with a sound problem in 64-bit version of Flash plugin in Fedora. After a few more reports and investigations, the source of the problem was located in glibc compiler in the memory-copying function.
Clarification paragraph: there are two memory copying functions, the difference is stated in the ANSI C standard: one function (memcpy) is allowed to behave unpredictably if source and destinations overlap and must be correct at all other times; the other (memmove) must always work correctly. It's been there for twenty years (actually, over thirty), and it's one of the first things that are learnt when studying C.
Since the memcpy function is fairly simple, for thirty years everybody had the idea how it works and how unpredictably it behaves in case of overlapping regions (and even built some tricks using). And so it was...until the last update to glibc, where the old function got some modern-processor optimizations (provided by Intel as they say). And it's the Adobe Flash plugin that was first (noticeably) affected by the compiler update.
There were three main proposals for solving the issue: reverting the changes to compiler, making memcpy an alias to memmove (so that it worked correctly at all times) or forcing Adobe gurus to fix their unsupported plugin. And while the last one seems to be the most correct, it has the direct impact on the end-user, who will have to wait for months with badly working sound, when some Adobe developer will have enough free time.
And the bug...well, according to documentation, it's not a bug and even hardly an incompatibility - it only breaks badly written apps. "The user doesn't care", though.
Moral: don't rely on anything with "undefined behaviour" even if you known how exactly it is undefined.
RU: за информацию спасибо http://avva.livejournal.com/2323823.html .