Ngx_array zero capacity support

Hello,

attached is a patch to make the ngx_array_push() support zero-capacity
arrays. Previously it would fail to grow the data buffer correctly (2

  • 0 = 0).

Hello!

On Fri, Sep 11, 2009 at 04:43:00PM +0200, Peter Schüller wrote:

Hello,

attached is a patch to make the ngx_array_push() support zero-capacity
arrays. Previously it would fail to grow the data buffer correctly (2

  • 0 = 0).

Could you please provide a use case where one should create array
without elements allocated?

Current nginx coding style suggest that arrays aren’t created
until needed, and initial allocation chunk must be at least 1.

Maxim D.

Hello,

attached is a patch to make the ngx_array_push() support zero-capacity
arrays. Previously it would fail to grow the data buffer correctly (2

  • 0 = 0).

Could you please provide a use case where one should create array
without elements allocated?

Not necessarily (I can dream up scenarios, but that doesn’t matter);
my phrasing in the original post was perhaps a bit misleading.

We had a case of this by accident and while debugging the resulting
problems realized that the array push gave us an invalid pointer. We
do not “need” this particular use case to be supported. However even
so, silently accepting the request and causing memory corruption is
IMO a bug. The request should either be serviced correctly, or an
error should be indicated.

Current nginx coding style suggest that arrays aren’t created
until needed, and initial allocation chunk must be at least 1.

Sure, which is what we do now and intended to do

An alternative fix is to just translate requests for arrays of
capacity 0 to be of capacity 1. And yet another is to fail the call.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs