File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -63,29 +63,27 @@ rb_imemo_tmpbuf_new(void)
6363}
6464
6565void *
66- rb_alloc_tmp_buffer_with_count (volatile VALUE * store , size_t size , size_t cnt )
66+ rb_alloc_tmp_buffer (volatile VALUE * store , long len )
6767{
68+ if (len < 0 ) {
69+ rb_raise (rb_eArgError , "negative buffer size (or size too big)" );
70+ }
71+
6872 /* Keep the order; allocate an empty imemo first then xmalloc, to
6973 * get rid of potential memory leak */
7074 rb_imemo_tmpbuf_t * tmpbuf = (rb_imemo_tmpbuf_t * )rb_imemo_tmpbuf_new ();
7175 * store = (VALUE )tmpbuf ;
72- void * ptr = ruby_xmalloc (size );
76+ void * ptr = ruby_xmalloc (len );
7377 tmpbuf -> ptr = ptr ;
74- tmpbuf -> size = size ;
78+ tmpbuf -> size = len ;
7579
7680 return ptr ;
7781}
7882
7983void *
80- rb_alloc_tmp_buffer (volatile VALUE * store , long len )
84+ rb_alloc_tmp_buffer_with_count (volatile VALUE * store , size_t size , size_t cnt )
8185{
82- long cnt ;
83-
84- if (len < 0 || (cnt = (long )roomof (len , sizeof (VALUE ))) < 0 ) {
85- rb_raise (rb_eArgError , "negative buffer size (or size too big)" );
86- }
87-
88- return rb_alloc_tmp_buffer_with_count (store , len , cnt );
86+ return rb_alloc_tmp_buffer (store , (long )size );
8987}
9088
9189void
Original file line number Diff line number Diff line change @@ -741,8 +741,7 @@ static inline void *
741741rb_alloc_tmp_buffer2 (volatile VALUE *store, long count, size_t elsize)
742742{
743743 const size_t total_size = rbimpl_size_mul_or_raise (RBIMPL_CAST ((size_t )count), elsize);
744- const size_t cnt = (total_size + sizeof (VALUE) - 1 ) / sizeof (VALUE);
745- return rb_alloc_tmp_buffer_with_count (store, total_size, cnt);
744+ return rb_alloc_tmp_buffer (store, (long )total_size);
746745}
747746
748747RBIMPL_SYMBOL_EXPORT_BEGIN ()
You can’t perform that action at this time.
0 commit comments