<meta http-equiv="Content-Type" content="text/html; charset=GB18030"><div><div>Hi,</div><div><br></div><div>I have been writing a nginx module recently, in which I use</div><div>ngx_buf_t to store data received from network, such as:</div><div><br></div><div>static u_char     buffer[4096];</div><div>static ngx_buf_t  b;</div><div><br></div><div>b.pos = b.last = b.start = buffer;</div><div>b.end = b.start + sizeof(buffer);</div><div><br></div><div>...</div><div><br></div><div>size = ngx_buf_size(&b);</div><div><br></div><div>then I find it not work since the parameter in ngx_buf_size is not</div><div>closed by parenthese. And I think this is a common situation so I</div><div>made this patch:</div><div><br></div><div># HG changeset patch</div><div># User balus <balus@foxmail.com></div><div># Date 1595073121 -28800</div><div>#      Sat Jul 18 19:52:01 2020 +0800</div><div># Node ID 92d9878c0c7549345f0a144cd81a6b6d45f21fc6</div><div># Parent  32a343635b50662979975e1204417bb1fc7e1b1f</div><div>Core: enclosed parameters of macros in parentheses.</div><div><br></div><div>diff -r 32a343635b50 -r 92d9878c0c75 src/core/ngx_buf.h</div><div>--- a/src/core/ngx_buf.h<span style="white-space:pre">       </span>Thu Jul 09 16:21:37 2020 +0300</div><div>+++ b/src/core/ngx_buf.h<span style="white-space:pre">        </span>Sat Jul 18 19:52:01 2020 +0800</div><div>@@ -125,20 +125,22 @@</div><div> #define NGX_CHAIN_ERROR     (ngx_chain_t *) NGX_ERROR</div><div> </div><div> </div><div>-#define ngx_buf_in_memory(b)        (b->temporary || b->memory || b->mmap)</div><div>-#define ngx_buf_in_memory_only(b)   (ngx_buf_in_memory(b) && !b->in_file)</div><div>+#define ngx_buf_in_memory(b)                                                 \</div><div>+    ((b)->temporary || (b)->memory || (b)->mmap)</div><div>+#define ngx_buf_in_memory_only(b)   (ngx_buf_in_memory(b) && !(b)->in_file)</div><div> </div><div> #define ngx_buf_special(b)                                                   \</div><div>-    ((b->flush || b->last_buf || b->sync)                                    \</div><div>-     && !ngx_buf_in_memory(b) && !b->in_file)</div><div>+    (((b)->flush || (b)->last_buf || (b)->sync)                              \</div><div>+     && !ngx_buf_in_memory(b) && !(b)->in_file)</div><div> </div><div> #define ngx_buf_sync_only(b)                                                 \</div><div>-    (b->sync                                                                 \</div><div>-     && !ngx_buf_in_memory(b) && !b->in_file && !b->flush && !b->last_buf)</div><div>+    ((b)->sync                                                               \</div><div>+     && !ngx_buf_in_memory(b)                                                \</div><div>+     && !(b)->in_file && !(b)->flush && !(b)->last_buf)</div><div> </div><div> #define ngx_buf_size(b)                                                      \</div><div>-    (ngx_buf_in_memory(b) ? (off_t) (b->last - b->pos):                      \</div><div>-                            (b->file_last - b->file_pos))</div><div>+    (ngx_buf_in_memory(b) ? (off_t) ((b)->last - (b)->pos)                   \</div><div>+                          : ((b)->file_last - (b)->file_pos))</div><div> </div><div> ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size);</div><div> ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs);</div><div><br></div></div>