Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09a45a19 authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Fix "adb devices -l".

Change 055f1aa4 switched to using isalnum(3)
but didn't take into account that isalnum has the opposite sense to the
function it replaced, so the tests should have been inverted.

Bug: http://b/20056546
Change-Id: I90630c0bea69ddbb4a95dc09f79f49d23fd497de
parent ea975880
Loading
Loading
Loading
Loading
+14 −17
Original line number Diff line number Diff line
@@ -772,7 +772,7 @@ void remove_transport_disconnect(atransport* t, adisconnect* dis)
}

static int qual_match(const char *to_test,
                      const char *prefix, const char *qual, int sanitize_qual)
                      const char *prefix, const char *qual, bool sanitize_qual)
{
    if (!to_test || !*to_test)
        /* Return true if both the qual and to_test are null strings. */
@@ -790,7 +790,7 @@ static int qual_match(const char *to_test,

    while (*qual) {
        char ch = *qual++;
        if (sanitize_qual && isalnum(ch))
        if (sanitize_qual && !isalnum(ch))
            ch = '_';
        if (ch != *to_test++)
            return 0;
@@ -823,9 +823,9 @@ retry:
        if (serial) {
            if ((t->serial && !strcmp(serial, t->serial)) ||
                (t->devpath && !strcmp(serial, t->devpath)) ||
                qual_match(serial, "product:", t->product, 0) ||
                qual_match(serial, "model:", t->model, 1) ||
                qual_match(serial, "device:", t->device, 0)) {
                qual_match(serial, "product:", t->product, false) ||
                qual_match(serial, "model:", t->model, true) ||
                qual_match(serial, "device:", t->device, false)) {
                if (result) {
                    if (error_out)
                        *error_out = "more than one device";
@@ -918,20 +918,17 @@ static const char *statename(atransport *t)
}

static void add_qual(char **buf, size_t *buf_size,
                     const char *prefix, const char *qual, int sanitize_qual)
                     const char *prefix, const char *qual, bool sanitize_qual)
{
    size_t len;
    int prefix_len;

    if (!buf || !*buf || !buf_size || !*buf_size || !qual || !*qual)
        return;

    len = snprintf(*buf, *buf_size, "%s%n%s", prefix, &prefix_len, qual);
    int prefix_len;
    size_t len = snprintf(*buf, *buf_size, "%s%n%s", prefix, &prefix_len, qual);

    if (sanitize_qual) {
        char *cp;
        for (cp = *buf + prefix_len; cp < *buf + len; cp++) {
            if (isalnum(*cp))
        for (char* cp = *buf + prefix_len; cp < *buf + len; cp++) {
            if (!isalnum(*cp))
                *cp = '_';
        }
    }
@@ -956,10 +953,10 @@ static size_t format_transport(atransport *t, char *buf, size_t bufsize,
        remaining -= len;
        buf += len;

        add_qual(&buf, &remaining, " ", t->devpath, 0);
        add_qual(&buf, &remaining, " product:", t->product, 0);
        add_qual(&buf, &remaining, " model:", t->model, 1);
        add_qual(&buf, &remaining, " device:", t->device, 0);
        add_qual(&buf, &remaining, " ", t->devpath, false);
        add_qual(&buf, &remaining, " product:", t->product, false);
        add_qual(&buf, &remaining, " model:", t->model, true);
        add_qual(&buf, &remaining, " device:", t->device, false);

        len = snprintf(buf, remaining, "\n");
        remaining -= len;