• Avid Amoeba@lemmy.ca
    link
    fedilink
    arrow-up
    17
    arrow-down
    1
    ·
    edit-2
    1 day ago

    Scary indeed.

    This one could be helped by always using this pattern whenever you write a function that returns a value, in any language, along with no early returns:

    int func(...) {
        int result = -1;
        ...
        return result;
    }
    

    I always start with writing my result default value, ideally indicating failure, and the return line. Then I implement the rest. We often don’t have the luxury of choosing the language we work with that has the features we like, but consistently enforced code style can help with a lot of problems. Anyone can make mistakes like the one in this bug regardless of experience so every little bit helps.