OSDN Git Service

rusty-gd: don't put payloads, the size has already been allocated
authorZach Johnson <zachoverflow@google.com>
Tue, 2 Feb 2021 02:34:47 +0000 (18:34 -0800)
committerZach Johnson <zachoverflow@google.com>
Tue, 2 Feb 2021 02:34:47 +0000 (18:34 -0800)
Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --rhost
Change-Id: Ie360848be3abef6b40573d04a2539eadd0d824d2

gd/packet/parser/packet_def.cc

index 97ce7ba..32b7be6 100644 (file)
@@ -995,7 +995,8 @@ void PacketDef::GenRustStructImpls(std::ostream& s) const {
       s << name_ << "DataChild::" << child->name_ << "(value) => value.write_to(buffer),";
     }
     if (fields_.HasPayload()) {
-      s << name_ << "DataChild::Payload(p) => buffer.put(&p[..]),";
+      auto offset = GetOffsetForField("payload");
+      s << name_ << "DataChild::Payload(p) => buffer[" << offset.bytes() << "..].copy_from_slice(&p[..]),";
     }
     s << name_ << "DataChild::None => {}";
     s << "}";