MrGlockenspiel / activate-linux

The "Activate Windows" watermark ported to Linux
GNU General Public License v3.0
4.41k stars 92 forks source link

Improve handling of colors #65

Closed ReperakDev closed 2 years ago

ReperakDev commented 2 years ago

I'm @MrGlockenspiel's friend so I get merge priority :trollface:

ReperakDev commented 2 years ago

Threat neutralized. Moving out

Ruby-Dragon commented 2 years ago

why did you use goto in the first place?

Ruby-Dragon commented 2 years ago

also, this is pretty good and I think we should merge @MrGlockenspiel

MrGlockenspiel commented 2 years ago

yeah i just didnt have time to look through it before yet

ReperakDev commented 2 years ago

why did you use goto in the first place?

A little late but it's because they're better in every way for error recovery. An oversimplified example is this:

int do_various_shit()
{
    char *foo = malloc(sizeof(char) * 50);

    int bar = get_bar();
    if (!bar) {
        return 1;
    }
    // just pretend that we used bar ;)

    free(foo);
    return 0;
}

See the problem here? If get_bar fails, foo is never freed.

We could fix it like this:

// snip
    int bar = get_bar();
    if (!bar) {
        free(foo);
        return 1;
    }
// snip
    free(foo);
    return 0;
// snip

But that's stupid and ineffcient.

Let's refactor it to use gotos.

int do_various_shit()
{
    int ret_code = 0;
    char *foo = malloc(sizeof(char) * 50);

    int bar = get_bar();
    if (!bar) {
        ret_code = 1;
        goto err;
    }

err:
    free(foo);
    return ret_code;
}

Much better.