Merge "GCC compiler warning fix for sprintf into snprintf" am: d2afbe4 am: 3b4af9a
am: 32fed55
* commit '32fed55e81c423480b96c6eeb70da11067777212':
GCC compiler warning fix for sprintf into snprintf
Change-Id: Iee25a662ffaa138196437aa48bd0dadf9ef381e8
diff --git a/fastboot/protocol.cpp b/fastboot/protocol.cpp
index 4850b4a..1785b76 100644
--- a/fastboot/protocol.cpp
+++ b/fastboot/protocol.cpp
@@ -54,14 +54,14 @@
while (true) {
int r = transport->Read(status, 64);
if (r < 0) {
- sprintf(ERROR, "status read failed (%s)", strerror(errno));
+ snprintf(ERROR, sizeof(ERROR), "status read failed (%s)", strerror(errno));
transport->Close();
return -1;
}
status[r] = 0;
if (r < 4) {
- sprintf(ERROR, "status malformed (%d bytes)", r);
+ snprintf(ERROR, sizeof(ERROR), "status malformed (%d bytes)", r);
transport->Close();
return -1;
}
@@ -80,7 +80,7 @@
if (!memcmp(status, "FAIL", 4)) {
if (r > 4) {
- sprintf(ERROR, "remote: %s", status + 4);
+ snprintf(ERROR, sizeof(ERROR), "remote: %s", status + 4);
} else {
strcpy(ERROR, "remote failure");
}
@@ -108,7 +108,7 @@
static int _command_start(Transport* transport, const char* cmd, uint32_t size, char* response) {
size_t cmdsize = strlen(cmd);
if (cmdsize > 64) {
- sprintf(ERROR, "command too large");
+ snprintf(ERROR, sizeof(ERROR), "command too large");
return -1;
}
@@ -117,7 +117,7 @@
}
if (transport->Write(cmd, cmdsize) != static_cast<int>(cmdsize)) {
- sprintf(ERROR, "command write failed (%s)", strerror(errno));
+ snprintf(ERROR, sizeof(ERROR), "command write failed (%s)", strerror(errno));
transport->Close();
return -1;
}
@@ -128,12 +128,12 @@
static int _command_data(Transport* transport, const void* data, uint32_t size) {
int r = transport->Write(data, size);
if (r < 0) {
- sprintf(ERROR, "data transfer failure (%s)", strerror(errno));
+ snprintf(ERROR, sizeof(ERROR), "data transfer failure (%s)", strerror(errno));
transport->Close();
return -1;
}
if (r != ((int) size)) {
- sprintf(ERROR, "data transfer failure (short transfer)");
+ snprintf(ERROR, sizeof(ERROR), "data transfer failure (short transfer)");
transport->Close();
return -1;
}
@@ -182,7 +182,7 @@
int fb_download_data(Transport* transport, const void* data, uint32_t size) {
char cmd[64];
- sprintf(cmd, "download:%08x", size);
+ snprintf(cmd, sizeof(cmd), "download:%08x", size);
return _command_send(transport, cmd, data, size, 0) < 0 ? -1 : 0;
}
@@ -216,7 +216,7 @@
if (len > TRANSPORT_BUF_SIZE) {
if (transport_buf_len > 0) {
- sprintf(ERROR, "internal error: transport_buf not empty\n");
+ snprintf(ERROR, sizeof(ERROR), "internal error: transport_buf not empty\n");
return -1;
}
to_write = round_down(len, TRANSPORT_BUF_SIZE);
@@ -230,7 +230,7 @@
if (len > 0) {
if (len > TRANSPORT_BUF_SIZE) {
- sprintf(ERROR, "internal error: too much left for transport_buf\n");
+ snprintf(ERROR, sizeof(ERROR), "internal error: too much left for transport_buf\n");
return -1;
}
memcpy(transport_buf, ptr, len);
@@ -257,7 +257,7 @@
}
char cmd[64];
- sprintf(cmd, "download:%08x", size);
+ snprintf(cmd, sizeof(cmd), "download:%08x", size);
int r = _command_start(transport, cmd, size, 0);
if (r < 0) {
return -1;