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

Commit 6d92997e authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Don't use VLAs in adb.

This makes no measurable difference to the sync time; "adb sync" of
everything on /system for a Nexus 9 still takes 20s.

Change-Id: Ifa2626f7453937e43856b9c4ee06e1f5db0aa273
parent b42e7e8f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ ADB_COMMON_CFLAGS := \
    -Wall -Wextra -Werror \
    -Wno-unused-parameter \
    -Wno-missing-field-initializers \
    -Wvla \
    -DADB_REVISION='"$(adb_version)"' \

# Define windows.h and tchar.h Unicode preprocessor symbols so that
+12 −11
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <utime.h>

#include <memory>
#include <vector>

#include "sysdeps.h"

@@ -101,14 +102,14 @@ class SyncConnection {

        // Sending header and payload in a single write makes a noticeable
        // difference to "adb sync" performance.
        char buf[sizeof(SyncRequest) + path_length];
        SyncRequest* req = reinterpret_cast<SyncRequest*>(buf);
        std::vector<char> buf(sizeof(SyncRequest) + path_length);
        SyncRequest* req = reinterpret_cast<SyncRequest*>(&buf[0]);
        req->id = id;
        req->path_length = path_length;
        char* data = reinterpret_cast<char*>(req + 1);
        memcpy(data, path_and_mode, path_length);

        return WriteFdExactly(fd, buf, sizeof(buf));
        return WriteFdExactly(fd, &buf[0], buf.size());
    }

    // Sending header, payload, and footer in a single write makes a huge
@@ -123,10 +124,10 @@ class SyncConnection {
            return false;
        }

        char buf[sizeof(SyncRequest) + path_length +
        std::vector<char> buf(sizeof(SyncRequest) + path_length +
                 sizeof(SyncRequest) + data_length +
                 sizeof(SyncRequest)];
        char* p = buf;
                 sizeof(SyncRequest));
        char* p = &buf[0];

        SyncRequest* req_send = reinterpret_cast<SyncRequest*>(p);
        req_send->id = ID_SEND;
@@ -147,7 +148,7 @@ class SyncConnection {
        req_done->path_length = mtime;
        p += sizeof(SyncRequest);

        if (!WriteFdExactly(fd, buf, (p-buf))) return false;
        if (!WriteFdExactly(fd, &buf[0], (p - &buf[0]))) return false;

        total_bytes += data_length;
        return true;
@@ -172,14 +173,14 @@ class SyncConnection {
    }

    bool ReportCopyFailure(const char* from, const char* to, const syncmsg& msg) {
        char buffer[msg.status.msglen + 1];
        if (!ReadFdExactly(fd, buffer, msg.status.msglen)) {
        std::vector<char> buf(msg.status.msglen + 1);
        if (!ReadFdExactly(fd, &buf[0], msg.status.msglen)) {
            fprintf(stderr, "adb: failed to copy '%s' to '%s'; failed to read reason (!): %s\n",
                    from, to, strerror(errno));
            return false;
        }
        buffer[msg.status.msglen] = 0;
        fprintf(stderr, "adb: failed to copy '%s' to '%s': %s\n", from, to, buffer);
        buf[msg.status.msglen] = 0;
        fprintf(stderr, "adb: failed to copy '%s' to '%s': %s\n", from, to, &buf[0]);
        return false;
    }

+2 −3
Original line number Diff line number Diff line
@@ -567,12 +567,11 @@ char* adb_strerror(int err) {

    // Lookup the string for an unknown error.
    char* errmsg = strerror(-1);
    char unknown_error[(errmsg == nullptr ? 0 : strlen(errmsg)) + 1];
    strcpy(unknown_error, errmsg == nullptr ? "" : errmsg);
    const std::string unknown_error = (errmsg == nullptr) ? "" : errmsg;

    // Lookup the string for this error to see if the C Runtime has it.
    errmsg = strerror(err);
    if ((errmsg != nullptr) && strcmp(errmsg, unknown_error)) {
    if (errmsg != nullptr && unknown_error != errmsg) {
        // The CRT returned an error message and it is different than the error
        // message for an unknown error, so it is probably valid, so use it.
    } else {