]> git.kaiwu.me - njs.git/commit
Fixed arrays expansion.
authorValentin Bartenev <vbart@nginx.com>
Wed, 8 May 2019 16:09:10 +0000 (19:09 +0300)
committerValentin Bartenev <vbart@nginx.com>
Wed, 8 May 2019 16:09:10 +0000 (19:09 +0300)
commitb0f23dbc4d4713f65470272768ef79b7cb47db78
treebe3ef78473983439fe631c91aca6a93127f09dbe
parentee6e4ac588c577eb2b9021c302f9f12369ecf8fa
Fixed arrays expansion.

There were two problems with njs_array_expand():

 1. It checked that the requred size with the appended elements wasn't bigger
    then the array size and then did nothing.  If there were elements removed
    from the beggining (by shift() operation), then "size <= array->size" can
    be true even if there wasn't enought free space after the array.

 2. After allocating more space to prepend elements, it set array->size without
    counting those elements.

Probably, the original idea was to decrement array->size while removing
elements from the beginning, but it wasn't done right.  Even if so, the
new version of the function looks cleaner.

This closes #152 and closes #153 issues on Github.
njs/njs_array.c
njs/test/njs_unit_test.c