News for hackers. Stuff that matters.
Re:size_t-to-int vulnerability in Linux’s filesystem layer by usefulcat on Tuesday July 20, 2021 @04:12PM (#27898658)
GCC's -Wconversion has some issues. For example, good luck getting gcc to /not/ emit a warning for this code, in C or C++. I have yet to find the appropriate cast to avoid a warning. Clang does not warn for this.

    typedef struct {
        unsigned value : 4;
    } S;

    void foo(S* s, unsigned value) {
        // error: conversion from 'unsigned int' to 'unsigned char:4' may change value
        s->value = value;
    }
I mean, I guess I can see the rationale.. it's just annoying to have to resort to using pragmas to turn off -Wconversion whenever I need to assign to a bitfield.
Re:size_t-to-int vulnerability in Linux’s filesystem layer by Denvercoder9 on Tuesday July 20, 2021 @04:36PM (#27898949)
Does it still warn if you do `s->value = value & 0x0F`? That seems like a reasonable alternative to pragmas if it works.
Re:size_t-to-int vulnerability in Linux’s filesystem layer by usefulcat on Wednesday July 21, 2021 @09:10AM (#27905731)
Thanks, that fixed it!
Re:size_t-to-int vulnerability in Linux’s filesystem layer by owl57 on Tuesday July 20, 2021 @09:19PM (#27901218)
It doesn't.