On Thu, 21 Feb 2013, Hannes Magnusson wrote:

> > @@ -305,6 +305,7 @@ static PHP_GINIT_FUNCTION(mongo)
> >  {
> >  	MonGlo(log_level) = 0;
> >  	MonGlo(log_module) = 0;
> > +	MonGlo(inc) = rand() & 0xFFFFFF;
> 
> What happens when rand() returns RAND_MAX and we generate couple of 
> new IDs (and therefore inc++) and we wind up with a integer larger 
> then 3bytes?

generate_id() handles that already:

    *I = (char*)&inc;
...
    /* inc */
    inc = MonGlo(inc);
    MonGlo(inc)++;
...
    /* 3 bytes inc */
    memcpy(data + 9, I + 1, 3);

It simply skips the first byte out of 4, then copies 3.

cheers,
Derick