odd char * arithmetic in nginx binary

Hassan Syed h.a.syed at gmail.com
Wed Oct 20 19:31:27 MSD 2010

I'm working on a authentication module and I need to produce a string
without any inherent fixed structure, so I would just using ngx_sprintf and
pointer arithmetic. However something insidious is going on during
compilation. I have played arround with u_char * as well as char *'s. The
gdb debug sessions goes as follows:

680    char * buf = (char *) ngx_palloc( r->pool, sz);
(gdb) n
681    if ( buf  == NULL)
(gdb) n
687    if( parameter_count > 0) {
(gdb) n
688        buf = (char *) ngx_sprintf((u_char *)buf,"%V?", &
(gdb) n
690        buf++; buf++;// buf++; buf++; buf++;
(gdb) p buf
$1 = 0x6d2de0 "lala?"
(gdb) n
698        if( parameters[i]->len != 0) {
(gdb) p buf
$2 = 0x6d2de7 ""

I should see 2 = 0x6d2de2 "la?"  as output

I have only incremented the char pointer twice, yet the pointer moves
forward 7 bytes (and when I do a +=5 it moves forward 10 bytes). I am hoping
someone can tell me what is going on here, as t his has
completely flabbergasted me.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx-devel/attachments/20101020/75ed1c39/attachment.html>

More information about the nginx-devel mailing list