Merge "Don\'t use VLAs in adb."

am: 24704399cd

* commit '24704399cdd58a396831fce2ba678642bd3a8ba5':
  Don't use VLAs in adb.
This commit is contained in:
Elliott Hughes 2015-10-27 22:52:26 +00:00 committed by android-build-merger
commit ebd5badd84
3 changed files with 15 additions and 14 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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 {