Print format for nevents

Hello,

nevents is an ngx_int_t, so the print format must be “%i”.

Regards,

yves

static ngx_int_t nevents;

— a/nginx-1.7.4/src/event/modules/ngx_poll_module.c
+++ b/nginx-1.7.4/src/event/modules/ngx_poll_module.c
@@ -201,7 +201,7 @@ ngx_poll_del_event(ngx_event_t *ev, ngx_int_t event,
ngx_uint_t flags)
if (ev->index < (ngx_uint_t) nevents) {

         ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
  •                       "index: copy event %ui to %i", nevents,
    

ev->index);

  •                       "index: copy event %i to %i", nevents,
    

ev->index);

         event_list[ev->index] = event_list[nevents];

Posted at Nginx Forum:

Hello!

On Wed, Aug 06, 2014 at 10:22:10AM -0400, crespin wrote:

Hello,

nevents is an ngx_int_t, so the print format must be “%i”.

Both signed and unsigned ngx_[u]int_t has the same size, so that’s
more about preferable representation of numbers, not about
correctness of the code.

In this particular case I think that %ui is better, as negative
numbers shouldn’t be here, and logging them with %ui will make
them clearly visible as very big positive numbers. It’s also what
will be used in the actual poll() syscall.

For future reference, please also take a look at the following
link:

http://nginx.org/en/docs/contributing_changes.html


Maxim D.
http://nginx.org/

Maxim D. Wrote:

correctness of the code.
Thanks for the link.

The format %d is used in another call to nevents.
To be consistent, should not use %ui ?

Regards,

yves

static ngx_int_t
ngx_poll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t
flags)

ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
“poll ready %d of %d”, ready, nevents);

Posted at Nginx Forum:

Hello!

On Wed, Aug 06, 2014 at 12:28:00PM -0400, crespin wrote:

Both signed and unsigned ngx_[u]int_t has the same size, so that’s
yves

static ngx_int_t
ngx_poll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t
flags)

ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
“poll ready %d of %d”, ready, nevents);

Yes, %d here is certainly incorrect, as int and ngx_int_t sizes
may differ. I don’t think there are any platforms with poll()
where this may cause problems, but nevertheless it’s worth fixing.
Changing this to %ui should be ok.

Care to provide a patch?


Maxim D.
http://nginx.org/

Hello!

On Thu, Aug 07, 2014 at 09:08:10AM -0400, crespin wrote:

where this may cause problems, but nevertheless it’s worth fixing.
Changing this to %ui should be ok.

HG changeset patch

User Yves Crespin[email protected]

Note: missing space before “<”. It’s either corruption introduced
by a forum interface, or a missing space in your ~/.hgrc.

In either case you may want to use nginx-devel@ list for further
patches, see Contributing Changes.

 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
  •               "poll ready %d of %d", ready, nevents);
    
  •               "poll ready %d of %ui", ready, nevents);
    

    if (err) {
    if (err == NGX_EINTR) {

Committed with commit log modified to match style we use, and
combined with other format specifier fixes from your other patch
(as well as a couple of fixes in the select module).

Thanks.


Maxim D.
http://nginx.org/

Hello,

here is the corresponding patch.

regards,

yves

Yes, %d here is certainly incorrect, as int and ngx_int_t sizes
may differ. I don’t think there are any platforms with poll()
where this may cause problems, but nevertheless it’s worth fixing.
Changing this to %ui should be ok.

HG changeset patch

User Yves Crespin[email protected]

Date 1407414744 -7200

Node ID c51d0d718b2177daaf14895840beb528e332418b

Parent ab48149b77a6bdbe47a8543c339cf84deeb8e341

use format %ui according to nevents type

diff -r ab48149b77a6 -r c51d0d718b21 src/event/modules/ngx_poll_module.c
— a/src/event/modules/ngx_poll_module.c Wed Aug 06 23:58:44 2014
+0900
+++ b/src/event/modules/ngx_poll_module.c Thu Aug 07 14:32:24 2014
+0200
@@ -268,7 +268,7 @@
}

 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
  •               "poll ready %d of %d", ready, nevents);
    
  •               "poll ready %d of %ui", ready, nevents);
    

    if (err) {
    if (err == NGX_EINTR) {

Posted at Nginx Forum: