raspberriesareyummy

joined 2 years ago
[–] raspberriesareyummy@lemmy.world 1 points 2 days ago* (last edited 2 days ago)

Don’t blame this on gcc or the library/function author - it is 100% user (i.e. programmer) error. Uninitialised memory of any type is undefined behaviour in the C and C++ abstract machine. That means optimising compilers can assume it does not exist.

I absolutely do blame this on the C++ standard being not specific enough, specifically for the way in how I learned about this: When writing a trivial function, you would never expect that - for a bool parameter - an "if (b)" branch can be executed as well as an "if (!b)" branch.

So basically, this mechanic sabotages input data validation in functions that test whether plausible parameters were provided. The problem is that a function you write that is bug-free and "perfect code" - despite input data validation - can exhibit undefined behavior due to an uninitialized bool type parameter. Something that can not happen with other uninitialized trivial (numeric) data types (int, float). Simply due to the way boolean checks are translated to x86 assembly:

Here's an example: https://godbolt.org/z/T3f9csohd

Note the assembly lines 176-182: The only difference for the "if (!b)" check is that the lowest bit of the boolean is flipped with an xor - which assumes about the implementation that a boolean can never hold values other than 0 or 1. Which I - as a naive user - also assumed until this happened. Correction: I assumed that negating a bool would result in the inverse boolean value.

So the problem boils down to: The value range of any given (built-in) numerical data type fully encloses the value range that an uninitialized variable of that type can have. This is not necessarily true for boolean: In g++, the value range is [0;1] and the range of an uninitialized bool is [0;255].

Accordingly, I would expect the C++ standard to fix this by stating that an uninitialized bool must have a value for which only one of two conditions evluates to true: b or !b, but not both.

[–] raspberriesareyummy@lemmy.world 5 points 3 days ago (2 children)

Been there, found undefined behavior where there should not be any. Imagine a function that takes a bool param with the following code, but neither branch gets executed:

if (b)
   doStuffForTrue();
if (!b)
   doStuffForFalse();

In a function that is passed an uninitialized bool parameter, in gcc compiler, both branches can get executed even when b is const. Reason: uninitialized bool in gcc can have values of a random integer, and while if(b) {} else ({} is guaranteed to execute only one branch, bool evaluations of a bool value take a "shortcut" that only has defined behavior with an initialized bool.

Same code with an uninitialized integer works as expected, btw.

[–] raspberriesareyummy@lemmy.world 15 points 3 days ago (1 children)

One way to contribute to FOSS is to improve bad documentation. You are correct, of course, and lazy devs write bad code if they do not cultivate good documentation - imho.

I'm not "against" it per se, but I would think - given the odds - it would be shitty to get tested without participating in the huge database.

[–] raspberriesareyummy@lemmy.world 20 points 1 week ago (1 children)

Wrong place and context.

[–] raspberriesareyummy@lemmy.world 2 points 1 week ago (1 children)

You promote hate against people based on what family they were born in. That - minus the actual violence - is what the Israeli government(!) is doing to the Palestinian people.

[–] raspberriesareyummy@lemmy.world -4 points 1 week ago (1 children)

It seems the doc validated your feelings that you wanted to help your friend then, but also set you up for disappointment by not telling you the odds, and that you were much more likely to be a match for some complete stranger.

[–] raspberriesareyummy@lemmy.world 3 points 1 week ago (3 children)

Let me quote you, you bigoted shithead:

https://lemmy.world/post/35390329/19201654 mnhs1 wrote:

They’d have to shoot me and force my dead body to eat anything touched by an Israeli. Fuck Arkansas.

[–] raspberriesareyummy@lemmy.world -3 points 1 week ago (2 children)

See you mentioned the important bit: we get checked to be in a large database pool for potential patients. Not to match with a specific friend, because as nice as that would be, it is very unlikely to ever happen.

[–] raspberriesareyummy@lemmy.world -3 points 1 week ago (3 children)

I am sorry but you misunderstood the process. You do not check whether you match with a specific patient, but rather typisation is done to add potential donors to a larger database, from which hopefully a donor match is already available even before, because the chances for a match are so low that you can have a couple million people checked until you find a match. This is not blood groups.

[–] raspberriesareyummy@lemmy.world 1 points 1 week ago (5 children)

Crossed the border from legitimate protests against Israeli war crimes in Gaza into anti-semitism.

view more: next ›