Weird code in ChangeSet 4c1b78



Hi,

    http://www.midnight-commander.org/changeset/4c1b78

I don't get why there has to be a variable k in the functions. Its
completely unnecessary. A much simpler, faster, and more reliable way is
the following (untested):

char *
unescape_string(const char *in) {
    GString *str;
    const char * src;
    char *result;

    str = g_string_new("");

    for (src = in; *src != '\0'; src++) {
        if (src[0] == '\\' && strchr(" \t*|;<>~#()?[]{}&", src[1])) {
            g_string_append_c(str, src[1]);
            src++;
        } else {
            g_string_append_c(str, src[0]);
        }
    }

    result = str->str;
    g_string_free(str, FALSE);
    return result;
}

It's much simpler that way. It doesn't call strlen() unnecessarily. It
doesn't have unneeded variables. And it doesn't crash if in[-1] is an
illegal address.

Roland


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]