From c0c7348e89726efc77f1fd7b9b5d555563b16313 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sun, 15 Dec 2019 12:29:52 -0800 Subject: [PATCH] fixup FixedBuf usage --- src/pvaproto.h | 3 ++- test/testsock.cpp | 18 +++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/pvaproto.h b/src/pvaproto.h index 31cabfe..9eda0a9 100644 --- a/src/pvaproto.h +++ b/src/pvaproto.h @@ -85,8 +85,9 @@ struct PVXS_API FixedBuf : public Buffer typedef Buffer base_type; virtual bool refill(size_t more) override final { return false; } + // for "uint8_t msg[] = "..."; // assumes extraneous trailing nil template - constexpr FixedBuf(bool be, uint8_t(&buf)[N]) :base_type(be, buf, N) {} + constexpr FixedBuf(bool be, uint8_t(&buf)[N]) :base_type(be, buf, N-1) {} constexpr FixedBuf(bool be, uint8_t* buf, size_t n) :base_type(be, buf, n) {} FixedBuf(bool be, std::vector& buf) :base_type(be, buf.data(), buf.size()) {} virtual ~FixedBuf(); diff --git a/test/testsock.cpp b/test/testsock.cpp index 5b18509..f0b1b56 100644 --- a/test/testsock.cpp +++ b/test/testsock.cpp @@ -104,7 +104,7 @@ void test_from_wire() { uint32_t val=0; - uint8_t buf[] = {0x12, 0x34, 0x56, 0x78, 0xff, 0xff}; + uint8_t buf[] = "\x12\x34\x56\x78\xff\xff"; FixedBuf pkt(true, buf); from_wire(pkt, val); @@ -115,7 +115,7 @@ void test_from_wire() { uint32_t val=0; - uint8_t buf[] = {0x78, 0x56, 0x34, 0x12, 0xff, 0xff}; + uint8_t buf[] = "\x78\x56\x34\x12\xff\xff"; FixedBuf pkt(false, buf); from_wire(pkt, val); @@ -126,8 +126,8 @@ void test_from_wire() { uint32_t val = 0; - uint8_t buf[] = {0x12, 0x34, 0x56, 0x78, 0xff, 0xff, 0xff, 0xff}; - FixedBuf pkt(true, buf, 2); + uint8_t buf[] = "\x12\x34"; + FixedBuf pkt(true, buf); from_wire(pkt, val); testEq(pkt.size(), 2u); @@ -137,7 +137,7 @@ void test_from_wire() { SockAddr val; - uint8_t buf[] = {0,0,0,0, 0,0,0,0, 0,0,0xff,0xff, 0x7f,0,0,1, 0xde, 0xad, 0xbe, 0xef}; + uint8_t buf[] = "\0\0\0\0\0\0\0\0\0\0\xff\xff\x7f\0\0\x01\xde\xad\xbe\xef"; FixedBuf pkt(true, buf); from_wire(pkt, val); @@ -154,7 +154,7 @@ void test_to_wire() { const uint32_t val = 0xdeadbeef; - uint8_t buf[8]; + uint8_t buf[8+1]; FixedBuf pkt(true, buf); to_wire(pkt, val); @@ -166,7 +166,7 @@ void test_to_wire() { const uint32_t val = 0xdeadbeef; - uint8_t buf[8]; + uint8_t buf[8+1]; FixedBuf pkt(false, buf); to_wire(pkt, val); @@ -178,7 +178,7 @@ void test_to_wire() { const SockAddr val(SockAddr::loopback(AF_INET)); - uint8_t buf[16+4]; + uint8_t buf[16+4+1]; FixedBuf pkt(true, buf); to_wire(pkt, val); @@ -191,7 +191,7 @@ void test_to_wire() { const uint32_t val = 0xdeadbeef; - uint8_t buf[8] = {0,0,0,0,0,0,0,0}; + uint8_t buf[] = "\0\0\0\0\0\0\0\0"; FixedBuf pkt(true, buf, 2); to_wire(pkt, val);