From 32f33ac62101f37de1133688b45c8eb837d5b8d8 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sun, 2 Jul 2006 06:15:38 +0000 Subject: [PATCH] =?utf8?q?Bugfix:=20se=20us=C3=A1=20data()=20en=20vez=20de?= =?utf8?q?=20c=5Fstr()=20para=20traducir=20los=20strings=20cuadno=20es=20n?= =?utf8?q?ecesario.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- practicas/pipi/src/devque.cpp | 2 +- practicas/pipi/src/devtcp.cpp | 2 +- practicas/pipi/src/ipheader.cpp | 2 +- practicas/pipi/src/nameserver.cpp | 2 +- practicas/pipi/src/resolvproto.cpp | 14 +++++++------- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/practicas/pipi/src/devque.cpp b/practicas/pipi/src/devque.cpp index 0791354..32b71a7 100644 --- a/practicas/pipi/src/devque.cpp +++ b/practicas/pipi/src/devque.cpp @@ -35,7 +35,7 @@ void DevQue::transmit(const std::string& data, const mac_type& mac) throw std::runtime_error("No se puede reservar memoria"); f->mac = mac; f->size = data.size(); - memcpy(f->frame, data.c_str(), data.size()); + memcpy(f->frame, data.data(), data.size()); int res = msgsnd(que_id, f, mtu + sizeof(size_t), 0); #ifdef DEBUG2 std::cout << "DevQue::transmit(msgtype/mac = " << f->mac << ", size = " diff --git a/practicas/pipi/src/devtcp.cpp b/practicas/pipi/src/devtcp.cpp index 828e0e6..e8828f4 100644 --- a/practicas/pipi/src/devtcp.cpp +++ b/practicas/pipi/src/devtcp.cpp @@ -41,7 +41,7 @@ void DevTCP::transmit(const std::string& data, const mac_type& mac) size_t size = data.size(); if (libtcp_send(tx_pool[mac], &size, sizeof(size_t)) != sizeof(size_t)) throw std::runtime_error("Error al enviar por el socket"); - if ((unsigned)libtcp_send(tx_pool[mac], data.c_str(), data.size()) != data.size()) + if ((unsigned)libtcp_send(tx_pool[mac], data.data(), data.size()) != data.size()) throw std::runtime_error("Error al enviar por el socket"); #ifdef DEBUG2 std::cout << "DevTCP::transmit(mac = " << mac << ", size = " diff --git a/practicas/pipi/src/ipheader.cpp b/practicas/pipi/src/ipheader.cpp index facc22b..60b1683 100644 --- a/practicas/pipi/src/ipheader.cpp +++ b/practicas/pipi/src/ipheader.cpp @@ -12,7 +12,7 @@ IPHeader::IPHeader(uint8_t version, uint16_t total_len, uint16_t id, bool df, IPHeader::IPHeader(const std::string& s) { - *this = *((IPHeader*)s.c_str()); + *this = *((IPHeader*)s.data()); } size_t IPHeader::header_len() diff --git a/practicas/pipi/src/nameserver.cpp b/practicas/pipi/src/nameserver.cpp index b007975..46e571c 100644 --- a/practicas/pipi/src/nameserver.cpp +++ b/practicas/pipi/src/nameserver.cpp @@ -367,7 +367,7 @@ void NameServer::recv_loop() if (proto == RESOLV_PROTO) // Si es para nosotros { rp_pkt_type_t type; - memcpy(&type, s.c_str(), sizeof(uint8_t)); + memcpy(&type, s.data(), sizeof(uint8_t)); switch (type) { // Request diff --git a/practicas/pipi/src/resolvproto.cpp b/practicas/pipi/src/resolvproto.cpp index f55bbf2..3b39419 100644 --- a/practicas/pipi/src/resolvproto.cpp +++ b/practicas/pipi/src/resolvproto.cpp @@ -11,10 +11,10 @@ ResolvProtoRequest::ResolvProtoRequest(std::string name, rp_pkt_type_t query_typ /// Constructor a partir de un buffer ResolvProtoRequest::ResolvProtoRequest(std::string buf) { - memcpy(&query_type, buf.c_str(), sizeof(uint8_t)); + memcpy(&query_type, buf.data(), sizeof(uint8_t)); uint16_t size; - memcpy(&size, buf.c_str() + sizeof(uint8_t), sizeof(uint16_t)); - name.assign(buf.c_str() + sizeof(uint8_t) + sizeof(uint16_t), size); + memcpy(&size, buf.data() + sizeof(uint8_t), sizeof(uint16_t)); + name.assign(buf.data() + sizeof(uint8_t) + sizeof(uint16_t), size); } /// Convierte a un buffer @@ -47,16 +47,16 @@ ResolvProtoResponse::ResolvProtoResponse(): ret(RP_RES_NOTFOUND), ttl(0) /// Constructor ResolvProtoResponse::ResolvProtoResponse(std::string buf) { - memcpy(&ret, buf.c_str(), sizeof(uint8_t)); - memcpy(&ttl, buf.c_str() + sizeof(uint8_t), sizeof(uint32_t)); + memcpy(&ret, buf.data(), sizeof(uint8_t)); + memcpy(&ttl, buf.data() + sizeof(uint8_t), sizeof(uint32_t)); uint8_t count; - memcpy(&count, buf.c_str() + sizeof(uint8_t) + sizeof(uint32_t), + memcpy(&count, buf.data() + sizeof(uint8_t) + sizeof(uint32_t), sizeof(uint8_t)); ips.reserve(count); for (uint8_t i = 0; i < count; ++i) { uint32_t ip; - memcpy(&ip, buf.c_str() + 2 * sizeof(uint8_t) + memcpy(&ip, buf.data() + 2 * sizeof(uint8_t) + sizeof(uint32_t) * (i + 1), sizeof(uint32_t)); ips.push_back(ip); } -- 2.43.0