@@ -190,25 +190,23 @@ TEST_CASE("coupon list: rejects malformed coupon count in bytes", "[coupon_list]
190190 const auto validBytes = sk1.serialize_compact ();
191191
192192 const uint8_t listCapacity = static_cast <uint8_t >(1u << hll_constants::LG_INIT_LIST_SIZE );
193- const uint8_t malformedCounts[] = {listCapacity, static_cast <uint8_t >(listCapacity + 2 )};
194- for (const uint8_t malformedCount: malformedCounts) {
195- auto sketchBytes = validBytes;
196- // Keep the input long enough to validate the declared LIST count.
197- const size_t requiredLen = hll_constants::LIST_INT_ARR_START
198- + malformedCount * sizeof (uint32_t );
199- if (sketchBytes.size () < requiredLen) {
200- sketchBytes.resize (requiredLen, 0 );
201- }
202- sketchBytes[hll_constants::LIST_COUNT_BYTE ] = malformedCount;
203-
204- REQUIRE_THROWS_AS (
205- hll_sketch::deserialize (sketchBytes.data (), sketchBytes.size ()),
206- std::invalid_argument);
207- REQUIRE_THROWS_AS (
208- CouponList<std::allocator<uint8_t >>::newList (
209- sketchBytes.data (), sketchBytes.size (), std::allocator<uint8_t >()),
210- std::invalid_argument);
193+ const uint8_t malformedCount = listCapacity;
194+ auto sketchBytes = validBytes;
195+ // Keep the input long enough to validate the declared LIST count.
196+ const size_t requiredLen = hll_constants::LIST_INT_ARR_START
197+ + malformedCount * sizeof (uint32_t );
198+ if (sketchBytes.size () < requiredLen) {
199+ sketchBytes.resize (requiredLen, 0 );
211200 }
201+ sketchBytes[hll_constants::LIST_COUNT_BYTE ] = malformedCount;
202+
203+ REQUIRE_THROWS_AS (
204+ hll_sketch::deserialize (sketchBytes.data (), sketchBytes.size ()),
205+ std::invalid_argument);
206+ REQUIRE_THROWS_AS (
207+ CouponList<std::allocator<uint8_t >>::newList (
208+ sketchBytes.data (), sketchBytes.size (), std::allocator<uint8_t >()),
209+ std::invalid_argument);
212210}
213211
214212TEST_CASE (" coupon list: rejects malformed coupon count in stream" , " [coupon_list]" ) {
@@ -218,34 +216,32 @@ TEST_CASE("coupon list: rejects malformed coupon count in stream", "[coupon_list
218216 sk1.update (2 );
219217
220218 const uint8_t listCapacity = static_cast <uint8_t >(1u << hll_constants::LG_INIT_LIST_SIZE );
221- const uint8_t malformedCounts[] = {listCapacity, static_cast <uint8_t >(listCapacity + 2 )};
222- for (const uint8_t malformedCount: malformedCounts) {
223- std::stringstream ss (std::ios::in | std::ios::out | std::ios::binary);
224- sk1.serialize_compact (ss);
225-
226- const size_t requiredLen = hll_constants::LIST_INT_ARR_START
227- + malformedCount * sizeof (uint32_t );
228- // Keep the stream long enough to validate the declared LIST count.
229- ss.seekp (0 , std::ios::end);
230- const auto endPos = static_cast <size_t >(ss.tellp ());
231- if (endPos < requiredLen) {
232- std::vector<char > pad (requiredLen - endPos, 0 );
233- ss.write (pad.data (), pad.size ());
234- }
235-
236- ss.seekp (hll_constants::LIST_COUNT_BYTE );
237- ss.put (static_cast <char >(malformedCount));
238-
239- ss.clear ();
240- ss.seekg (0 );
241- REQUIRE_THROWS_AS (hll_sketch::deserialize (ss), std::invalid_argument);
242-
243- ss.clear ();
244- ss.seekg (0 );
245- REQUIRE_THROWS_AS (
246- CouponList<std::allocator<uint8_t >>::newList (ss, std::allocator<uint8_t >()),
247- std::invalid_argument);
219+ const uint8_t malformedCount = listCapacity;
220+ std::stringstream ss (std::ios::in | std::ios::out | std::ios::binary);
221+ sk1.serialize_compact (ss);
222+
223+ const size_t requiredLen = hll_constants::LIST_INT_ARR_START
224+ + malformedCount * sizeof (uint32_t );
225+ // Keep the stream long enough to validate the declared LIST count.
226+ ss.seekp (0 , std::ios::end);
227+ const auto endPos = static_cast <size_t >(ss.tellp ());
228+ if (endPos < requiredLen) {
229+ std::vector<char > pad (requiredLen - endPos, 0 );
230+ ss.write (pad.data (), pad.size ());
248231 }
232+
233+ ss.seekp (hll_constants::LIST_COUNT_BYTE );
234+ ss.put (static_cast <char >(malformedCount));
235+
236+ ss.clear ();
237+ ss.seekg (0 );
238+ REQUIRE_THROWS_AS (hll_sketch::deserialize (ss), std::invalid_argument);
239+
240+ ss.clear ();
241+ ss.seekg (0 );
242+ REQUIRE_THROWS_AS (
243+ CouponList<std::allocator<uint8_t >>::newList (ss, std::allocator<uint8_t >()),
244+ std::invalid_argument);
249245}
250246
251247} /* namespace datasketches */
0 commit comments