-
Notifications
You must be signed in to change notification settings - Fork 568
n_alloc has wrong value in buf_append function #54
Description
Hi,
This was reported by a Debian user in Bug 761250
The buf_append function will check if the current buf size needs
additional memory to append the new element(s).
n_alloc seems for how many ELEMENTS after append the new element(s),
so it is just a count number, and do not need to multiply with the
element size.
File: buf.c: http://sources.debian.net/src/flex/2.5.39-8/buf.c/#L245
241 /* May need to alloc more. /
242 if (n_elem + buf->nelts > buf->nmax) {
243
244 / exact amount needed... /
245 n_alloc = (n_elem + buf->nelts) * buf->elt_size;
246
247 / ...plus some extra */
248 if (((n_alloc * buf->elt_size) % 512) != 0
249 && buf->elt_size < 512)
250 n_alloc +=
251 (512 -
252 ((n_alloc * buf->elt_size) % 512)) /
253 buf->elt_size;
Check line 245, n_alloc should direct equals n_elem + buf->nelts, the
additional multiply with buf->elt_size should be a mistake, because in
line 248 and below, when checking the 512 boundaries, the n_alloc will
multiply with the buf->elt_size.
manoj