WTF Bites



  • @Bulb said in WTF Bites:

    And before you say there is no static assert in C, there is

    There is also that C11 thing, though negative-size array is a cool trick when target compiler is not newfangled enough.




  • Fake News

    Thinking about making a salad with balsamic vinegar dressing. Realizing that I'm nearly out of balsamic vinegar. Then I'm thinking of the reason for said shortage from a while ago...

    Apparently my brother noticed that this bottle had been sitting on the shelf for quite a while and came to the conclusion that it's syrupy appearance was a sign that it had gone off.

    This of course ignores that 1) it's vinegar, anything in there is either dead or likely meant to improve the flavour, 2) the Italian stuff is meant to look like that because they start with cooked grape must, then mature it for a bit. It's not abnormal that it looks slightly stickier than usual wine vinegar.

    Luckily he was too lazy to empty it out completely or rinse it with hot water, but that was still half a bottle (and likely $5-10) literally down the drain... :facepalm:



  • @JBert said in WTF Bites:

    vinegar

    Dammit. I knew there was something I was forgetting when I went to the store... (quickly writes it down for next time)

    edit: PSA: Don't go to the store on your lunch hour. It will take at least that long because of the checkout line. I was only 5 minutes late to our group meeting.



  • @levicki said in WTF Bites:

    Just let your dog or cat have at the headset so they think you are there.

    "👴: Are there any questions?"
    "🐈: Meow?"
    "🐕: Woof!"



  • @dkf: you can also use a union that includes your bitfield and an uint32_t integer. That way, you don't have to calculate the number of padding bits.

    Edit: hmm, wait. I'm not sure if accesses to the bitfield would be 8-bit or 32-bit wide in that case. There's a potential gotcha there.



  • @Gąska said in WTF Bites:

    @dkf TIL Windows 95 could run with 4MB RAM.

    I did run Win95 on a 386 laptop with 4 MB RAM and a compressed 80 MB hard disk at one point. It required Zen-like patience, of course, but it did work.


  • Discourse touched me in a no-no place

    @aitap said in WTF Bites:

    @Bulb said in WTF Bites:

    And before you say there is no static assert in C, there is

    There is also that C11 thing, though negative-size array is a cool trick when target compiler is not newfangled enough.

    The target compiler (gcc) is new enough, even on our test platforms. However, my IDE horks at me if I try (known issue that I found last night and :kneeling_warthog: for finding the link now), and I don't want to maintain two kinds of static assertion.


  • Discourse touched me in a no-no place

    @Zerosquare said in WTF Bites:

    @dkf: you can also use a union that includes your bitfield and an uint32_t integer. That way, you don't have to calculate the number of padding bits.

    I do that in some cases, generally where I have a complex piece of multilayer encoding to handle. (That stuff all worked first time, FWIW.)

    Edit: hmm, wait. I'm not sure if accesses to the bitfield would be 8-bit or 32-bit wide in that case. There's a potential gotcha there.

    A critical part of doing stuff with bitfields is that you make all fields in the struct the same underlying type (uint in my case, which is typedef'd to the same thing as uint32_t by a header I depend on). Mixing bitfield field types is a recipe for very strange padding behaviour that is almost certainly not what you want. This was a bunch of trouble I knew about before starting on this little sub-project.

    What you're trying to do is:
    union {
        struct {
            uint32_t field ; 12;
            uint32_t field2 ; 12;
            uint_32_t : 8; // padding; unnamed because you don't want code to access dead bits
        } bitfield;
        uint32_t whole_word;
    };
    

    And yes it works well provided the platform ABI locks down field ordering right. The embedded ARM ABI does this very nicely. Yes, the C standard doesn't require it to, but it does anyway (and that makes a ton of sense for a platform meant for poking around with custom hardware).

    Technically, the padding can be omitted in this case. However, I want it there to specifically document that the bits are to be ignored and are not just neglected by happenstance.


  • Notification Spam Recipient

    @dkf said in WTF Bites:

    A critical part of doing stuff with bitfields is that you make all fields in the struct the same underlying type

    Yeah, I was looking into if it was possible to take an array of bools and make them a bitfield, but that doesn't seem to be possible without much trickery and shenanigans. Would be nice, because then one of my configs could fit in a single byte instead of eight in memory, but for now I'm not worrying about the wasted RAM (a total of up to 48 bytes if all possible modules are enabled).


  • Discourse touched me in a no-no place

    @Tsaukpaetra Oh, it is, and it's trivially easy on all platforms provided you don't need the binary form of the structure to be portable to all the rest. You only ever need to be careful if you are interfacing with external stuff (like hardware or other programs).

    struct all_the_flags_t {
        bool flag1 : 1;
        bool flag2 : 1;
        bool flag3 : 1;
        bool flag4 : 1;
        // etc. 
        bool flag47 : 1;
        bool flag48 : 1;
    };
    

    In this case, you'd expect the structure to end up 6 bytes long, occupying 8 bytes in an array because of alignment requirements. Things only get tricky once you are dealing with mixed bitfield types (that's defined, but not always helpful). General guidance of mine: put all the fields of the same type together if you can, and group the bitfields together (while bearing in mind where word boundaries are), as that tends to encourage the compiler to use maximally efficient packing. And don't use signed bitfields because they're crazy, and categorically don't put const on any fields unless every bitfield in the struct is constant.

    Saving a few bytes here and there in a structure isn't too important… until you have a lot of instances of the structure (or it's some bitmapped hardware horror). All bitfields really do is let the compiler generate the shifts and masks for you.


  • BINNED

    @Tsaukpaetra said in WTF Bites:

    @dkf said in WTF Bites:

    A critical part of doing stuff with bitfields is that you make all fields in the struct the same underlying type

    Yeah, I was looking into if it was possible to take an array of bools and make them a bitfield, but that doesn't seem to be possible without much trickery and shenanigans. Would be nice, because then one of my configs could fit in a single byte instead of eight in memory, but for now I'm not worrying about the wasted RAM (a total of up to 48 bytes if all possible modules are enabled).

    If you're not restricted to plain C:


  • Discourse touched me in a no-no place

    @topspin said in WTF Bites:

    If you're not restricted to plain C

    Alas, I am.

    C++ can run on the target platform, but only in very heavily stripped down form as there's hard maximum of 32kB on the size of TEXT segment and no shared libraries. It's tricky to get the C++ standard library to shrink down quite that small while leaving enough room for application code. (We also have a severely stripped C library; Win32 or POSIX this ain't! The largest programs we run have about 128 bytes of free space after building in production mode.)


  • Java Dev

    @dkf said in WTF Bites:

    @Zerosquare said in WTF Bites:

    @dkf: you can also use a union that includes your bitfield and an uint32_t integer. That way, you don't have to calculate the number of padding bits.

    I do that in some cases, generally where I have a complex piece of multilayer encoding to handle. (That stuff all worked first time, FWIW.)

    Edit: hmm, wait. I'm not sure if accesses to the bitfield would be 8-bit or 32-bit wide in that case. There's a potential gotcha there.

    A critical part of doing stuff with bitfields is that you make all fields in the struct the same underlying type (uint in my case, which is typedef'd to the same thing as uint32_t by a header I depend on). Mixing bitfield field types is a recipe for very strange padding behaviour that is almost certainly not what you want. This was a bunch of trouble I knew about before starting on this little sub-project.

    What you're trying to do is:
    union {
        struct {
            uint32_t field ; 12;
            uint32_t field2 ; 12;
            uint_32_t : 8; // padding; unnamed because you don't want code to access dead bits
        } bitfield;
        uint32_t whole_word;
    };
    

    And yes it works well provided the platform ABI locks down field ordering right. The embedded ARM ABI does this very nicely. Yes, the C standard doesn't require it to, but it does anyway (and that makes a ton of sense for a platform meant for poking around with custom hardware).

    Technically, the padding can be omitted in this case. However, I want it there to specifically document that the bits are to be ignored and are not just neglected by happenstance.

    I used to have a utility called pdwtags. It prints structure layouts and other things based on the dwarf debug information in a compiled binary. Unfortunately it's not in my yum repos and the old build I did manually on RHEL5 produces garbage output.



  • Ssh supports ed25519 keys since version 6.5 released 6 years ago. I've been using them as default for at least 4 years. 2 years ago the above bug that TeamCity does not accept them was filed. TeamCity still does not support them.



  • @levicki said in WTF Bites:

    The best time to go shopping is during meetings!

    Except this was one where I was being actively asked questions... (our group sprint planning)



  • @dkf said in WTF Bites:

    let the compiler generate the shifts and masks for you

    I've pretty much always done that myself (and just about all code I've ever seen for 30+ years does, too), because when you're dealing with hardware, the shifts and masks absolutely have to be consistent and match the hardware. While a particular compiler may do it right, in general it's not guaranteed.


  • Notification Spam Recipient

    @dkf said in WTF Bites:

    Oh, it is,

    That's not what I was talking about. I want to turn the following into a single byte, accessible as if it were an array:

    bool SignalResponseConfig[4][2];
    

    To my understanding, it is impossible to specify that this means eight bits.


  • Java Dev

    @Tsaukpaetra said in WTF Bites:

    @dkf said in WTF Bites:

    Oh, it is,

    That's not what I was talking about. I want to turn the following into a single byte, accessible as if it were an array:

    bool SignalResponseConfig[4][2];
    

    To my understanding, it is impossible to specify that this means eight bits.

    Possibly related to the fact you can't have a pointer to something smaller than a byte.



  • @levicki said in WTF Bites:

    However, when it comes to making sure Microsoft websites (Sharepoint, Office portal, etc) work, it's a fucking nightmare.

    Maybe they are doing it on purpose so you would finally give up, enable everything, and let their analytics servers receive your precious telemetry data you have been withholding for so long.

    :tinfoil-hat: Don't attribute to incompetence what can be attributed to malice :tinfoil-hat:


  • Considered Harmful

    @aitap said in WTF Bites:

    Don't attribute to incompetence what can be attributed to malice

    This is WTDWTF, so... :why_not_both:



  • WTF of my day: So, I'm at my parents' home and my father asked me to help him look at some electrical problems.

    Namely, the upper floor has a separate built-in kitchen with an electrical oven, a fridge and a dish washer. And for some time now, the circuit breaker for this kitchen triggers all the time - you can't even reset it because it will immediately trigger again.

    My father suspected that it was the fridge causing this so we set out to pull the fridge out of its recess. This turned out to be a bit of a problem: The usual way this works is that you simply remove the front paneling and then pull out the appliance. In this case we had to first remove the paneling, them remove about 20 other screws holding the fridge in place (clearly we reside in an earthquake-prone area).

    And still got stuck about halfway through because the geniuses who installed the kitchen had, for some Glodforsaken reason, glued wood to the side of the fridge using silicone. Probably to remove any possibility of movement due to earthquakes. So we had to take a really long knife and kind-of saw through the silicone.

    After a lot of cursing we finally got the stupid thing out. And were confronted with this:

    1c2907f8-4007-42cb-8275-417fa6ba5e3b-image.png

    So, yeah, the fridge was not the cause for the short circuit. Which left the dishwasher (the oven is on a circuit all of its own using three-phase). That one turned out to work just fine.

    In fact when we tried it, the circuit breaker didn't trigger in any way? :wat:

    So, we plugged in the fridge and - bzzt - the breaker triggered. :wat::wat:

    Oh, and it wasn't the power outlets - we used various combinations, even from other rooms and other circuits using extension cables.

    In essence, something triggered the breaker which turned out to be the fridge but couldn't be because the fridge wasn't plugged in.


  • ♿ (Parody)

    @Tsaukpaetra said in WTF Bites:

    @dkf said in WTF Bites:

    Oh, it is,

    That's not what I was talking about. I want to turn the following into a single byte, accessible as if it were an array:

    bool SignalResponseConfig[4][2];
    

    To my understanding, it is impossible to specify that this means eight bits.

    It seems like something should be possible in C++ with some creative operator overloading. If nothing else it would make amusing content for us.



  • @Rhywden said in WTF Bites:

    WTF of my day: So, I'm at my parents' home and my father asked me to help him look at some electrical problems.

    Namely, the upper floor has a separate built-in kitchen with an electrical oven, a fridge and a dish washer. And for some time now, the circuit breaker for this kitchen triggers all the time - you can't even reset it because it will immediately trigger again.

    My father suspected that it was the fridge causing this so we set out to pull the fridge out of its recess. This turned out to be a bit of a problem: The usual way this works is that you simply remove the front paneling and then pull out the appliance. In this case we had to first remove the paneling, them remove about 20 other screws holding the fridge in place (clearly we reside in an earthquake-prone area).

    And still got stuck about halfway through because the geniuses who installed the kitchen had, for some Glodforsaken reason, glued wood to the side of the fridge using silicone. Probably to remove any possibility of movement due to earthquakes. So we had to take a really long knife and kind-of saw through the silicone.

    After a lot of cursing we finally got the stupid thing out. And were confronted with this:

    1c2907f8-4007-42cb-8275-417fa6ba5e3b-image.png

    So, yeah, the fridge was not the cause for the short circuit. Which left the dishwasher (the oven is on a circuit all of its own using three-phase). That one turned out to work just fine.

    In fact when we tried it, the circuit breaker didn't trigger in any way? :wat:

    So, we plugged in the fridge and - bzzt - the breaker triggered. :wat::wat:

    Oh, and it wasn't the power outlets - we used various combinations, even from other rooms and other circuits using extension cables.

    In essence, something triggered the breaker which turned out to be the fridge but couldn't be because the fridge wasn't plugged in.

    I would guess that the act of pulling the fridge out also pulled the plug out if it's socket.



  • @Carnage Unlikely - the cable is about 2 meters long.


  • Notification Spam Recipient

    @boomzilla said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @dkf said in WTF Bites:

    Oh, it is,

    That's not what I was talking about. I want to turn the following into a single byte, accessible as if it were an array:

    bool SignalResponseConfig[4][2];
    

    To my understanding, it is impossible to specify that this means eight bits.

    It seems like something should be possible in C++ with some creative operator overloading. If nothing else it would make amusing content for us.

    .....no brain, you stop right there!


  • Notification Spam Recipient

    @Rhywden said in WTF Bites:

    because the fridge wasn't plugged in.

    Was it operational prior to removal?



  • @Rhywden said in WTF Bites:

    @Carnage Unlikely - the cable is about 2 meters long.

    Snagged on something on the fridge.



  • @Carnage Not possible either - it's a closed unit with no protuding parts. In short: Whatever else you want to suggest, it will not be possible.


  • Fake News

    @Carnage said in WTF Bites:

    @Rhywden said in WTF Bites:

    @Carnage Unlikely - the cable is about 2 meters long.

    Snagged on something on the fridge.

    This would be my guess as well, though you would have to inspect the fridge's plug to see if by any chance you could see any corrosion or scratch marks on them. If you can see that they corroded or darkened slightly except for where they would have been in contact with the wall socket then you know that it was plugged in.



  • @boomzilla said in WTF Bites:

    It seems like something should be possible in C++ with some creative operator overloading. If nothing else it would make amusing content for us.

    See std::vector<bool>. Returns proxy objects when indexed with operator[].

    Filed under: It probably seemed like a good idea at the time.


  • BINNED

    @Rhywden
    It's haunted.



  • @Luhmann said in WTF Bites:

    @Rhywden
    It's haunted.

    "The Tale of the Haunted Fridge" sounds like something from the front page.



  • @Rhywden said in WTF Bites:

    @Carnage Not possible either - it's a closed unit with no protuding parts. In short: Whatever else you want to suggest, it will not be possible.

    It doesn't stand on the floor?


  • Java Dev

    @cvi said in WTF Bites:

    @boomzilla said in WTF Bites:

    It seems like something should be possible in C++ with some creative operator overloading. If nothing else it would make amusing content for us.

    See std::vector<bool>. Returns proxy objects when indexed with operator[].

    Filed under: It probably seemed like a good idea at the time.

    Sometimes easiest is best.

    typedef uint64_t * bitmask_t;
    static inline int  bm_test (bitmask_t * bm, size_t i) { bm[i / 64]  &  (1ULL << (i % 64)); }
    static inline void bm_set  (bitmask_t * bm, size_t i) { bm[i / 64] |=  (1ULL << (i % 64)); }
    static inline void bm_reset(bitmask_t * bm, size_t i) { bm[i / 64] &= ~(1ULL << (i % 64)); }
    

    Though I recognize that is not C++ code, it probably has a close relative which is.


  • :belt_onion:

    @Rhywden said in WTF Bites:

    In essence, something triggered the breaker which turned out to be the fridge but couldn't be because the fridge wasn't plugged in.

    Was the refrigerator made by Microsoft? :trollface:



  • I felt like putting my userscripts on GitHub, and while I'm here, why not let them update themselves as well? So I created a repo with a @downloadURL in the metadata and updated version, manually set the downloadURL in my installed script, checked for update, and... nothing. Tried uninstalling, emptying the recycle bin, and going directly to the raw .user.js in GitHub, which the extension intercepted. Somehow, it managed to pick up the old version without the @downloadURL. Even though the current version on Github has it.

    Can someone check and tell me if there's something obvious I'm missing?

    e: After posting this, I tried getting the raw file off github again and it magically worked, or at least got the new version with the url. I'll try updating the script and see if it actually works.

    e2: It does. I guess there's a few minutes of lag either from github or browser cache or something.


  • BINNED

    @cvi said in WTF Bites:

    @boomzilla said in WTF Bites:

    It seems like something should be possible in C++ with some creative operator overloading. If nothing else it would make amusing content for us.

    See std::vector<bool>. Returns proxy objects when indexed with operator[].

    Filed under: It probably seemed like a good idea at the time.

    You could do a multidimensional version (for fixed size dimensions like in std::array) where all but the last indexing operator return a proxy accumulating the indices, and the final one computes the one-dimensional index equivalent which then indexes into an appropriately sized std::bitset.


  • :belt_onion:

    Apparently, Cloudflare doesn't allow the mention of the Windows command processor
    ( cmd.exe) due to . . . . raisins.

    I was on another forum asking a question about compatibility between their product and cmd.exe and when I tried to submit my question I got this:

    oops-1.png

    So I checked the browser console:

    Untitled-2.png

    :sideways_owl:



  • @El_Heffe Probably an optional "feature" that you can disable... I hope.



  • @levicki said in WTF Bites:

    Fuck Mozilla.

    :womm: Seriously, it did. All I did was 'add account' in tbird and it "just worked". Yes, it popped up the browser window, but it took my password. (I just did this on a new machine a couple weeks ago)

    The big thing is then adding Lightning and "Provider for Google Calendar" so I can use my goggle calendar. But that "just worked" too.

    Oh just remembered... I may have had to enable something in gmail first. But I would have done that so long ago (years!) that I don't remember for sure...


  • Discourse touched me in a no-no place

    @levicki said in WTF Bites:

    Proper way is to disallow apps from using main password, enable 2-factor, generate app-specific passwords for apps you use and use those.

    Or stop making your life difficult and enable 2FA while letting email clients that support it use the main password.



  • @levicki said in WTF Bites:

    visit most famous Windows hacking forum, download script to install Windows Store into Windows 10 Enterprise LTSC, and download Mail & Calendar app from the store, then set GMail there

    Were there no other email clients that you could install without hacking the Windows store?



  • @levicki said in WTF Bites:

    And have them store the main password somewhere where nalware can get it? Why would I do that when Google made application passwords jin order to avoid that? Also I don't want to use 2FA for email, just for the account itself.

    If it prompted you for Oauth then you would've just been typing your password into Google, assuming you can trust Mozilla to not package a keylogger with their app :tinfoil-hat:

    @levicki said in WTF Bites:

    What free email client would you recommend?

    I don't know, I've never used em. Here's some blogspam I found with a quick search that's got four of them other than MS and Thunderbird



  • @levicki said in WTF Bites:

    And asking me for SMS code next due to 2FA being on?

    Yeah, or the Google "Is this you?" prompt on your phone. That's how you login to Google. It then generates a token that doesn't include your password and sends it back to your app.



  • @levicki said in WTF Bites:

    @dcon said in WTF Bites:

    I may have had to enable something in gmail first

    Yes, you enabled applications to use main account password, which is horribly insecure.

    Proper way is to disallow apps from using main password, enable 2-factor, generate app-specific passwords for apps you use and use those.

    That's not how it's supposed to work. I have 2FA for company Microsoft account, which has similar mechanism. The apps that can show the OAuth dialog are always authorized that way and that is more secure and recommended practice. Those applications don't remember the password, but get a refresh token, so they remain logged in—which applies also to the web apps.

    The generated password is for applications that can't show the OAuth dialog, so can't use 2FA—which is all the MS Office apps except Teams. Thunderbird uses OAuth, and only OAuth, because that's what new applications integrating with Google account are supposed to do. You shouldn't be using application password with it, you should just use the 2FA.



  • @levicki said in WTF Bites:

    @hungrier said in WTF Bites:

    If it prompted you for Oauth then you would've just been typing your password into Google

    And asking me for SMS code next due to 2FA being on? Give it a rest already.

    Yes. Only once. Then it has the refresh token.

    App passwords are better. You can issue separate ones for each mail app you use and revoke each one separately. You can change main account password and not have to propagate that change in all email apos on various devices you use.

    When showing the OAuth dialog, the application never ever gets to know the password at all, but stays logged in by virtue of having a refresh token. There is a list of the extant refresh tokens somewhere in the account management panel and you can revoke it by simply clikcing delete next to it. Much simpler than app passwords.

    App passwords are for legacy apps that don't support OAuth only. Thunderbird does support OAuth, so it's not supposed to use app password.


  • Discourse touched me in a no-no place

    @levicki said in WTF Bites:

    And have them store the main password somewhere where nalware can get it? Why would I do that when Google made application passwords jin order to avoid that?

    It's OAuth2, it's not storing the password.

    By Google's own definition application passwords are for applications that don't support 2FA. Thunderbird supports 2FA.


  • Discourse touched me in a no-no place

    @Bulb said in WTF Bites:

    Thunderbird uses OAuth, and only OAuth, because that's what new applications integrating with Google account are supposed to do.

    Even Thunderbird lets you use the normal password for POP, it's only IMAP it forces Oauth for.



  • @levicki

    1. Why does he even have a 2FA if he has problems operating it?
    2. Forwarding the SMS to you, then?
    3. You had to go through the hassle of getting logged in to the account before anyway to generate the app password, so nothing is simplified anyway.
    4. When Microsoft eventually gets their act together and fix their application, expect the same problem with it, because they use OAuth an 2FA the same way and they'll want to eventually switch the users too.
    5. I am certain Mozilla tests the installation process. Much better than Microsoft who fired most of their QA anyway. What they don't test is the upgrade path from password authentication to OAuth2, possibly because all users should be long switched by now. Microsoft is still to do that in future and it's unlikely they'll test it more than Mozilla did.

Log in to reply