Changeset 2131

Show
Ignore:
Timestamp:
03/20/2008 05:33:22 PM (6 months ago)
Author:
stbuehler
Message:

fix many (64-bit) format warnings and unsigned/signed compare warnings

Observations:

  • 32-bit platform (linux):
    • size_t: 32-bit unsigned
    • ssize_t: 32-bit signed (should always be the same size as size_t)
    • off_t: 64-bit signed (should be always signed)

(it is 64 bit as we use LARGE_FILE options, without we couldn't handle files > 4GB)

  • 64-bit platform:
    • size_t: 64-bit unsigned
    • ssize_t: 64-bit signed
    • off_t: 64-bit signed

Fixes:

  • off_t will be casted to (intmax_t) and formatted with "%jd"
  • size_t gets formatted with "%zu"
  • ssize_t gets formatted witz "%zd"
  • off_t/size_t comparisons: This is no problem if off_t is bigger then size_t; the compiler will just case size_t to off_t which is no problem in that case.

Now, on 64-bit they have the same size but differ in signedness; i cast
size_t to off_t manually anyway and just hope, that no one is using such big
numbers (on 64-bit this is a really big number).
This was mostly in mmap code, and as we only mmap small chunks i don't think this
is a problem.

Location:
trunk
Files:
23 modified

Legend:

Unmodified
Added
Removed
  • trunk/NEWS

    r2117 r2131  
    2222  * mod_cgi: add a event-handler for STDERR_FILENO and log it with ERROR() 
    2323  * fixed building/testing outside of the src dir 
     24  * fix many (64-bit) format warnings and unsigned/signed compare warnings 
    2425 
    2526- 1.5.0-r19.. - 
  • trunk/src/connections.c

    r2060 r2131  
    13391339                                         
    13401340                                        if (cq_len > 0) { 
    1341                                                 TRACE("filter[%d] is not empty: %lld (report me)", f->id, cq_len); 
     1341                                                TRACE("filter[%d] is not empty: %jd (report me)", f->id, (intmax_t) cq_len); 
    13421342                                        } 
    13431343                                } 
  • trunk/src/fdevent_poll.c

    r1827 r2131  
    117117                        if (ev->pollfds[ndx].revents & POLLNVAL) { 
    118118                                /* should never happen */ 
    119                                 SEGFAULT("ev->pollfds[%d].revents has POLLNVAL", ndx); 
     119                                SEGFAULT("ev->pollfds[%zu].revents has POLLNVAL", ndx); 
    120120                        } 
    121121 
  • trunk/src/http-header-glue.c

    r1930 r2131  
    280280                                                /* check if we can safely copy the string */ 
    281281                                                if (used_len >= sizeof(buf)) { 
    282                                                         TRACE("last-mod check failed as timestamp was too long: %s: %d, %d", 
     282                                                        TRACE("last-mod check failed as timestamp was too long: %s: %zu, %zu", 
    283283                                                                        BUF_STR(http_if_modified_since->value), 
    284284                                                                        used_len, sizeof(buf) - 1); 
  • trunk/src/http_req.c

    r2060 r2131  
    158158                                t->is_key = 1; 
    159159                        } else { 
    160                                 ERROR("CR with out LF at pos: %d", t->offset); 
     160                                ERROR("CR with out LF at pos: %zu", t->offset); 
    161161                                return PARSER_ERROR; 
    162162                        } 
     
    185185                                t->offset == t->lookup_offset + 1) { 
    186186 
    187                                 ERROR("invalid char (%d) at pos: %d", c, t->offset); 
     187                                ERROR("invalid char (%d) at pos: %zu", c, t->offset); 
    188188                                return PARSER_ERROR; 
    189189                        } 
  • trunk/src/http_req_range_test.c

    r1496 r2131  
    22#include <assert.h> 
    33#include <string.h> 
     4#include <stdint.h> 
    45 
    56#include <tap.h> 
     
    1819        ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "0-0"); 
    1920        for (r = ranges; r; r = r->next) { 
    20                 diag(".. %lld - %lld", r->start, r->end); 
     21                diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end); 
    2122        } 
    2223        http_request_range_reset(ranges); 
     
    2526        ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "1-2,3-4"); 
    2627        for (r = ranges; r; r = r->next) { 
    27                 diag(".. %lld - %lld", r->start, r->end); 
     28                diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end); 
    2829        } 
    2930        http_request_range_reset(ranges); 
     
    3233        ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "-0"); 
    3334        for (r = ranges; r; r = r->next) { 
    34                 diag(".. %lld - %lld", r->start, r->end); 
     35                diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end); 
    3536        } 
    3637        http_request_range_reset(ranges); 
     
    3940        ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "0-"); 
    4041        for (r = ranges; r; r = r->next) { 
    41                 diag(".. %lld - %lld", r->start, r->end); 
     42                diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end); 
    4243        } 
    4344        http_request_range_reset(ranges); 
     
    4647        ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "0-0,0-"); 
    4748        for (r = ranges; r; r = r->next) { 
    48                 diag(".. %lld - %lld", r->start, r->end); 
     49                diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end); 
    4950        } 
    5051        http_request_range_reset(ranges); 
     
    5354        ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "0-0,-0"); 
    5455        for (r = ranges; r; r = r->next) { 
    55                 diag(".. %lld - %lld", r->start, r->end); 
     56                diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end); 
    5657        } 
    5758        http_request_range_reset(ranges); 
     
    6061        ok(PARSE_SUCCESS == http_request_range_parse(b, ranges), "1-2,3-4,5-"); 
    6162        for (r = ranges; r; r = r->next) { 
    62                 diag(".. %lld - %lld", r->start, r->end); 
     63                diag(".. %jd - %jd", (intmax_t) r->start, (intmax_t) r->end); 
    6364        } 
    6465 
  • trunk/src/lempar.c

    r2048 r2131  
    211211const char *ParseTokenName(int tokenType){ 
    212212#ifndef NDEBUG 
    213   if( tokenType>0 && ((unsigned int)tokenType)<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){ 
     213  if( tokenType>0 && ((size_t)tokenType)<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){ 
    214214    return yyTokenName[tokenType]; 
    215215  }else{ 
     
    336336  } 
    337337  i += iLookAhead; 
    338   if( i<0 || (unsigned int)i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ 
     338  if( i<0 || (size_t)i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ 
    339339#ifdef YYFALLBACK 
    340340    int iFallback;            /* Fallback token */ 
     
    379379  } 
    380380  i += iLookAhead; 
    381   if( i<0 || (unsigned int)i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ 
     381  if( i<0 || (size_t)i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ 
    382382    return yy_default[stateno]; 
    383383  }else{ 
     
    457457#ifndef NDEBUG 
    458458  if( yyTraceFILE && yyruleno>=0 
    459         && (unsigned int) yyruleno<sizeof(yyRuleName)/sizeof(yyRuleName[0]) ){ 
     459        && (size_t) yyruleno<sizeof(yyRuleName)/sizeof(yyRuleName[0]) ){ 
    460460    fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt, 
    461461      yyRuleName[yyruleno]); 
  • trunk/src/mod_accesslog.c

    r1916 r2131  
    343343# ifdef HAVE_SYSLOG_H 
    344344                                        if (s->access_logbuffer->used > 2) { 
    345                                                 syslog(LOG_INFO, "%*s", s->access_logbuffer->used - 2, s->access_logbuffer->ptr); 
     345                                                syslog(LOG_INFO, "%*s", (int) s->access_logbuffer->used - 2, s->access_logbuffer->ptr); 
    346346                                        } 
    347347# endif 
     
    547547                                if (s->access_logbuffer->used > 2) { 
    548548                                        /* syslog appends a \n on its own */ 
    549                                         syslog(LOG_INFO, "%*s", s->access_logbuffer->used - 2, s->access_logbuffer->ptr); 
     549                                        syslog(LOG_INFO, "%*s", (int) s->access_logbuffer->used - 2, s->access_logbuffer->ptr); 
    550550                                } 
    551551#endif 
     
    829829                        if (b->used > 2) { 
    830830                                /* syslog appends a \n on its own */ 
    831                                 syslog(LOG_INFO, "%*s", b->used - 2, b->ptr); 
     831                                syslog(LOG_INFO, "%*s", (int) b->used - 2, b->ptr); 
    832832                        } 
    833833#endif 
  • trunk/src/mod_chunked.c

    r2060 r2131  
    203203        } 
    204204        if(con->response.content_length >= 0) { 
    205                 if (p->conf.debug > 0) TRACE("response content length known, disabling chunked encoding.  len=%ju", con->response.content_length); 
     205                if (p->conf.debug > 0) TRACE("response content length known, disabling chunked encoding.  len=%jd", (intmax_t) con->response.content_length); 
    206206                use_chunked = 0; 
    207207        } else if (con->request.http_method != HTTP_METHOD_HEAD) { 
     
    347347        } 
    348348 
    349         if (hctx->debug > 1) TRACE("chunk encoded: in=%lld, out=%lld", in->bytes_out, out->bytes_in); 
     349        if (hctx->debug > 1) TRACE("chunk encoded: in=%jd, out=%jd", (intmax_t) in->bytes_out, (intmax_t) out->bytes_in); 
    350350 
    351351        chunkqueue_remove_finished_chunks(in); 
  • trunk/src/mod_compress.c

    r2060 r2131  
    650650        /* don't compress files that are too large as we need to much time to handle them */ 
    651651        if (max_fsize && (sce->st.st_size >> 10) > max_fsize) { 
    652                 if (con->conf.log_request_handling) TRACE("file '%s' is too large: %ju",  
     652                if (con->conf.log_request_handling) TRACE("file '%s' is too large: %jd",  
    653653                                BUF_STR(con->physical.path),  
    654                                 sce->st.st_size); 
     654                                (intmax_t) sce->st.st_size); 
    655655 
    656656                return HANDLER_GO_ON; 
     
    659659        /* compressing the file might lead to larger files instead */ 
    660660        if (sce->st.st_size < 128) { 
    661                 if (con->conf.log_request_handling) TRACE("file '%s' is too small: %ju",  
     661                if (con->conf.log_request_handling) TRACE("file '%s' is too small: %jd",  
    662662                                BUF_STR(con->physical.path),  
    663                                 sce->st.st_size); 
     663                                (intmax_t) sce->st.st_size); 
    664664 
    665665                return HANDLER_GO_ON; 
  • trunk/src/mod_deflate.c

    r2060 r2131  
    104104 
    105105typedef struct { 
    106         int bytes_in; 
     106        off_t bytes_in; 
    107107        filter *fl; 
    108108        chunkqueue *in; 
     
    360360                        buffer_copy_memory(hctx->output, gzip_header, sizeof(gzip_header)); 
    361361                        if(p->conf.debug) { 
    362                                 TRACE("gzip_header len=%i", sizeof(gzip_header)); 
     362                                TRACE("gzip_header len=%zu", sizeof(gzip_header)); 
    363363                        } 
    364364                        /* initialize crc32 */ 
     
    753753        off_t toSend; 
    754754        stat_cache_entry *sce = NULL; 
    755         off_t we_want_to_mmap = 2 MByte;  
    756         off_t we_want_to_send = st_size; 
     755        size_t we_want_to_mmap = 2 MByte;  
     756        size_t we_want_to_send = st_size; 
    757757        char *start = NULL; 
    758758 
     
    766766         
    767767        if (c->file.length + c->file.start > sce->st.st_size) { 
    768                 ERROR("file '%s' was shrinked: was %lld, is %lld (%lld, %lld)",  
    769                                 BUF_STR(c->file.name), c->file.length + c->file.start, sce->st.st_size, 
    770                                 c->file.start, c->offset); 
     768                ERROR("file '%s' was shrinked: was %ju, is %ju (%ju, %ju)",  
     769                                BUF_STR(c->file.name), (intmax_t) c->file.length + c->file.start, (intmax_t) sce->st.st_size, 
     770                                (intmax_t) c->file.start, (intmax_t) c->offset); 
    771771                 
    772772                return -1; 
     
    812812                        c->file.mmap.offset = 0; 
    813813 
    814                         while (c->file.mmap.offset + we_want_to_mmap < c->file.start) { 
     814                        while (c->file.mmap.offset + (off_t) we_want_to_mmap < c->file.start) { 
    815815                                c->file.mmap.offset += we_want_to_mmap; 
    816816                        } 
     
    858858        /* to_send = abs_mmap_end - abs_offset */ 
    859859        toSend = (c->file.mmap.offset + c->file.mmap.length) - (abs_offset); 
    860         if(toSend > we_want_to_send) toSend = we_want_to_send; 
     860        if (toSend > (off_t) we_want_to_send) toSend = we_want_to_send; 
    861861 
    862862        if (toSend < 0) { 
     
    898898 
    899899        if(p->conf.debug && hctx->bytes_in < hctx->out->bytes_in) { 
    900                 TRACE("compressing uri '%s' increased the sent content-size from %i to %lld", 
    901                         BUF_STR(con->uri.path_raw), hctx->bytes_in, hctx->out->bytes_in); 
     900                TRACE("compressing uri '%s' increased the sent content-size from %jd to %jd", 
     901                        BUF_STR(con->uri.path_raw), (intmax_t) hctx->bytes_in, (intmax_t) hctx->out->bytes_in); 
    902902        } 
    903903 
     
    10121012 
    10131013        if (p->conf.debug) { 
    1014                 TRACE("end: %d - %lld - %lld", hctx->in->is_closed, hctx->in->bytes_in, hctx->in->bytes_out); 
     1014                TRACE("end: %d - %jd - %jd", hctx->in->is_closed, (intmax_t) hctx->in->bytes_in, (intmax_t) hctx->in->bytes_out); 
    10151015        } 
    10161016 
  • trunk/src/mod_postgresql_vhost.c

    r1756 r2131  
    220220        gchar *field; 
    221221 
     222        UNUSED(host); 
     223 
    222224        /* no host specified? */ 
    223225        if (buffer_is_empty(con->uri.authority)) return HANDLER_ERROR; 
     
    259261 
    260262                if (PQstatus(p->conf.conn) != CONNECTION_OK){ 
    261                         ERROR("PQconnectdb() failed: %s", PQstatus(p->conf.conn)); 
     263                        ERROR("PQconnectdb() failed: %i", PQstatus(p->conf.conn)); 
    262264 
    263265                        PQfinish(p->conf.conn); 
  • trunk/src/mod_proxy_backend_ajp13.c

    r2060 r2131  
    282282        len = ajp13_decode_int(data); 
    283283        if ((ssize_t)len == -1) { 
    284                 ERROR("ajp13_decode_int() returned invalid len: %d", len); 
     284                ERROR("ajp13_decode_int() returned invalid len: %zu", len); 
    285285                return len; 
    286286        } 
    287287#ifdef AJP13_DEBUG 
    288         TRACE("ajp13_decode_string() string-len: %d (is_header: %d, common-header: %d)", len, is_header, (len & AJP13_COMMON_HEADER_CODE)); 
     288        TRACE("ajp13_decode_string() string-len: %zu (is_header: %d, common-header: %zd)", len, is_header, (len & AJP13_COMMON_HEADER_CODE)); 
    289289#endif 
    290290 
     
    295295                        len = strlen(p); 
    296296                } else { 
    297                         ERROR("ajp13_decode_string() can't resolve common-header: %d", len & ~AJP13_COMMON_HEADER_CODE); 
     297                        ERROR("ajp13_decode_string() can't resolve common-header: %zd", len & ~AJP13_COMMON_HEADER_CODE); 
    298298 
    299299                        return -1; 
     
    303303        if (p == NULL) { 
    304304                if ((data->buf->used - data->offset) <= (len + 1)) { 
    305                         ERROR("we have %ju bytes, but a partial-string wants %zu. no way", (data->buf->used - data->offset), len); 
     305                        ERROR("we have %jd bytes, but a partial-string wants %zu. no way", (intmax_t) (data->buf->used - data->offset), len); 
    306306                        return -1; 
    307307                } 
  • trunk/src/mod_proxy_backend_fastcgi.c

    r2060 r2131  
    480480                out->is_closed = 1; 
    481481 
    482                 TRACE("%ju / %ju -> %d",  
    483                                 in->bytes_in, in->bytes_out, 
     482                TRACE("%jd / %jd -> %d",  
     483                                (intmax_t) in->bytes_in, (intmax_t) in->bytes_out, 
    484484                                in->is_closed); 
    485485 
  • trunk/src/mod_uploadprogress.c

    r2060 r2131  
    260260 
    261261        if (b->used != 32 + 1) { 
    262                 if (p->conf.debug) ERROR("the Progress-ID has to be 32 characters long, got %d characters", b->used - 1); 
     262                if (p->conf.debug) ERROR("the Progress-ID has to be 32 characters long, got %zd characters", b->used - 1); 
    263263                return NULL; 
    264264        } 
  • trunk/src/network_gthread_aio.c

    r2060 r2131  
    250250 
    251251                        /* check which chunks are finished now */ 
    252                         for (tc = c; tc; tc = tc->next) { 
    253                                 /* finished the chunk */ 
    254                                 if (tc->offset == tc->mem->used - 1) { 
    255                                         /* skip the first c->next as that will be done by the c = c->next in the other for()-loop */ 
    256                                         if (chunk_finished) { 
    257                                                 c = c->next; 
    258                                         } else { 
    259                                                 chunk_finished = 1; 
    260                                         } 
     252                        for (tc = c; tc && chunk_is_done(tc); tc = tc->next) { 
     253                                /* skip the first c->next as that will be done by the c = c->next in the other for()-loop */ 
     254                                if (chunk_finished) { 
     255                                        c = c->next; 
    261256                                } else { 
    262                                         break; 
     257                                        chunk_finished = 1; 
    263258                                } 
    264259                        } 
     
    386381                                                        return NETWORK_STATUS_FATAL_ERROR; 
    387382                                                } else if (r != c->file.copy.length) { 
    388                                                         ERROR("read() returned %d instead of %ju", r, c->file.copy.length); 
     383                                                        ERROR("read() returned %zd instead of %jd", r, (intmax_t) c->file.copy.length); 
    389384                         
    390385                                                        return NETWORK_STATUS_FATAL_ERROR; 
     
    421416                                        return NETWORK_STATUS_CONNECTION_CLOSE; 
    422417                                default: 
    423                                         ERROR("write failed: %d (%s) [%lld, %p, %lld]",  
    424                                                         errno, strerror(errno), c->file.copy.length, c->file.mmap.start, c->file.copy.offset); 
     418                                        ERROR("write failed: %d (%s) [%jd, %p, %jd]",  
     419                                                        errno, strerror(errno), (intmax_t) c->file.copy.length, 
     420                                                        c->file.mmap.start, (intmax_t) c->file.copy.offset); 
    425421                                        return NETWORK_STATUS_FATAL_ERROR; 
    426422                                } 
     
    436432                        cq->bytes_out += r; 
    437433 
    438                         if (c->file.mmap.length == c->file.copy.offset) { 
     434                        if (c->file.copy.offset == (off_t) c->file.mmap.length) { 
    439435                                /* this block is sent, get a new one */ 
    440436                                timing_log(srv, con, TIME_SEND_WRITE_END); 
  • trunk/src/network_gthread_sendfile.c

    r2060 r2131  
    170170 
    171171                        /* check which chunks are finished now */ 
    172                         for (tc = c; tc; tc = tc->next) { 
    173                                 /* finished the chunk */ 
    174                                 if (tc->offset == tc->mem->used - 1) { 
    175                                         /* skip the first c->next as that will be done by the c = c->next in the other for()-loop */ 
    176                                         if (chunk_finished) { 
    177                                                 c = c->next; 
    178                                         } else { 
    179                                                 chunk_finished = 1; 
    180                                         } 
     172                        for (tc = c; tc && chunk_is_done(tc); tc = tc->next) { 
     173                                /* skip the first c->next as that will be done by the c = c->next in the other for()-loop */ 
     174                                if (chunk_finished) { 
     175                                        c = c->next; 
    181176                                } else { 
    182                                         break; 
     177                                        chunk_finished = 1; 
    183178                                } 
    184179                        } 
  • trunk/src/network_linux_sendfile.c

    r1697 r2131  
    4545 
    4646                        /* check which chunks are finished now */ 
    47                         for (tc = c; tc; tc = tc->next) { 
    48                                 /* finished the chunk */ 
    49                                 if (tc->offset == tc->mem->used - 1) { 
    50                                         /* skip the first c->next as that will be done by the c = c->next in the other for()-loop */ 
    51                                         if (chunk_finished) { 
    52                                                 c = c->next; 
    53                                         } else { 
    54                                                 chunk_finished = 1; 
    55                                         } 
     47                        for (tc = c; tc && chunk_is_done(tc); tc = tc->next) { 
     48                                /* skip the first c->next as that will be done by the c = c->next in the other for()-loop */ 
     49                                if (chunk_finished) { 
     50                                        c = c->next; 
    5651                                } else { 
    57