question on some simple codes in ngx_buf.c

microwish nginx-forum at nginx.us
Thu Jan 16 07:04:45 UTC 2014


Hello there,

code snippet in the definition of ngx_chain_add_copy in ngx_buf.c:


    ll = chain;
                                                                            
                                                                            
                         
    for (cl = *chain; cl; cl = cl->next) {
        ll = &cl->next;
    }


Why is ll assigned repeatedly? I'm sorry for failed thinking out any
necessity.

And I modified the above as the following. Is it OK?


    if (*chain) {
        for (cl = *chain; cl->next; cl = cl->next) { /* void */ }
        ll = &cl->next;
    } else {
        ll = chain;
    }


Thank you very much.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,246499,246499#msg-246499



More information about the nginx mailing list