This repository was archived by the owner on Mar 22, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
include/libpmemobj++/detail Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -109,9 +109,17 @@ struct ringbuf_t {
109109 /* Set by ringbuf_consume, reset by ringbuf_release. */
110110 bool consume_in_progress;
111111
112+ /* *
113+ * Creates new ringbuf_t instance.
114+ *
115+ * Length must be < RBUF_OFF_MASK
116+ */
112117 ringbuf_t (size_t max_workers, size_t length)
113118 : workers(new ringbuf_worker_t [max_workers])
114119 {
120+ if (length >= RBUF_OFF_MASK)
121+ throw std::out_of_range (" ringbuf length too big" );
122+
115123 written.store (0 );
116124 next.store (0 );
117125 end.store (0 );
Original file line number Diff line number Diff line change @@ -314,6 +314,22 @@ test_random(void)
314314 delete r;
315315}
316316
317+ static void
318+ test_size ()
319+ {
320+ try {
321+ auto size = (1ULL << 32 ) + 1 ;
322+ auto r = new ringbuf_t (1 , size);
323+ (void )r;
324+
325+ ASSERT_UNREACHABLE;
326+ } catch (std::out_of_range &) {
327+
328+ } catch (...) {
329+ ASSERT_UNREACHABLE;
330+ }
331+ }
332+
317333int
318334main (void )
319335{
@@ -326,5 +342,6 @@ main(void)
326342 test_multi ();
327343 test_overlap ();
328344 test_random ();
345+ test_size ();
329346 return 0 ;
330347}
You can’t perform that action at this time.
0 commit comments