]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: switch buffer sizes and offsets to size_t
authorWilly Tarreau <w@1wt.eu>
Wed, 18 Jul 2018 08:07:58 +0000 (10:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:39 +0000 (16:23 +0200)
Passing unsigned ints everywhere is painful, and will cause some headache
later when we'll want to integrate better with struct ist which already
uses size_t. Let's switch buffers to use size_t instead.

include/common/buf.h
src/buffer.c
src/checks.c
src/flt_http_comp.c
src/mux_h2.c
src/stream.c

index 998e31aa14e93cd1d463feb98dd0ce842c70f228..4c372debfb109d4828c645d11661bca7b98fd824 100644 (file)
 #ifndef _COMMON_BUF_H
 #define _COMMON_BUF_H
 
+#include <stdint.h>
+
 
 /* Structure defining a buffer's head */
 struct buffer {
        char *p;                    /* buffer's start pointer, separates in and out data */
-       unsigned int size;          /* buffer size in bytes */
-       unsigned int i;             /* number of input bytes pending for analysis in the buffer */
-       unsigned int o;             /* number of out bytes the sender can consume from this buffer */
+       size_t size;                /* buffer size in bytes */
+       size_t i;                   /* number of input bytes pending for analysis in the buffer */
+       size_t o;                   /* number of out bytes the sender can consume from this buffer */
        char data[0];               /* <size> bytes of stored data */
 };
 
index 79cc133cb6cbdb4382121323c3420b3b20a5d125..b6ece4ba67ecc3909943b0d8cf4c16b2a92331e2 100644 (file)
@@ -211,9 +211,9 @@ void buffer_slow_realign(struct buffer *buf)
 void buffer_dump(FILE *o, struct buffer *b, int from, int to)
 {
        fprintf(o, "Dumping buffer %p\n", b);
-       fprintf(o, "            data=%p o=%d i=%d p=%p\n"
+       fprintf(o, "            data=%p o=%u i=%u p=%p\n"
                    "            relative:   p=0x%04x\n",
-               b->data, b->o, b->i, b->p, (unsigned int)(b->p - b->data));
+               b->data, (unsigned int)b->o, (unsigned int)b->i, b->p, (unsigned int)(b->p - b->data));
 
        fprintf(o, "Dumping contents from byte %d to byte %d\n", from, to);
        fprintf(o, "         0  1  2  3  4  5  6  7    8  9  a  b  c  d  e  f\n");
index 3cae94d517d1d5debbfb9bccbb913bfa402a5cb3..0150bbb7eeac3a396e872238d4845408dfd8900b 100644 (file)
@@ -2854,8 +2854,8 @@ static int tcpcheck_main(struct check *check)
                        }
 
                        if (check->current_step->string_len >= check->bo->size) {
-                               chunk_printf(&trash, "tcp-check send : string too large (%d) for buffer size (%d) at step %d",
-                                            check->current_step->string_len, check->bo->size,
+                               chunk_printf(&trash, "tcp-check send : string too large (%d) for buffer size (%u) at step %d",
+                                            check->current_step->string_len, (unsigned int)check->bo->size,
                                             tcpcheck_get_step_id(check));
                                set_server_check_status(check, HCHK_STATUS_L7RSP, trash.str);
                                goto out_end_tcpcheck;
index b93ff69e8c662f738889dfae254e76619ab7f12a..99a767c926c663a788991860a04946bc37575c9f 100644 (file)
@@ -298,8 +298,8 @@ comp_http_forward_data(struct stream *s, struct filter *filter,
        if (msg->flags & HTTP_MSGF_TE_CHNK) {
                ret = http_compression_buffer_add_data(st, tmpbuf, zbuf, tmpbuf->i);
                if (ret != tmpbuf->i) {
-                       ha_warning("HTTP compression failed: Must consume %d bytes but only %d bytes consumed\n",
-                                  tmpbuf->i, ret);
+                       ha_warning("HTTP compression failed: Must consume %u bytes but only %d bytes consumed\n",
+                                  (unsigned int)tmpbuf->i, ret);
                        return -1;
                }
        }
index 5fc754721643ce256499236e66883823486e9e21..1eba104b3d72d1f99b7a874d5a9088dfee44d776 100644 (file)
@@ -3357,7 +3357,7 @@ static int h2s_frt_make_resp_data(struct h2s *h2s, struct buffer *buf)
        }
 
  end:
-       trace("[%d] sent simple H2 DATA response (sid=%d) = %d bytes out (%d in, st=%s, ep=%u, es=%s, h2cws=%d h2sws=%d) buf->o=%d", h2c->st0, h2s->id, size+9, total, h1_msg_state_str(h1m->state), h1m->err_pos, h1_msg_state_str(h1m->err_state), h2c->mws, h2s->mws, buf->o);
+       trace("[%d] sent simple H2 DATA response (sid=%d) = %d bytes out (%d in, st=%s, ep=%u, es=%s, h2cws=%d h2sws=%d) buf->o=%u", h2c->st0, h2s->id, size+9, total, h1_msg_state_str(h1m->state), h1m->err_pos, h1_msg_state_str(h1m->err_state), h2c->mws, h2s->mws, (unsigned int)buf->o);
        return total;
 }
 
@@ -3472,7 +3472,7 @@ static void h2_show_fd(struct chunk *msg, struct connection *conn)
        }
 
        chunk_appendf(msg, " st0=%d flg=0x%08x nbst=%u nbcs=%u fctl_cnt=%d send_cnt=%d tree_cnt=%d orph_cnt=%d dbuf=%u/%u mbuf=%u/%u",
-                     h2c->st0, h2c->flags, h2c->nb_streams, h2c->nb_cs, fctl_cnt, send_cnt, tree_cnt, orph_cnt, h2c->dbuf->i, h2c->dbuf->size, h2c->mbuf->o, h2c->mbuf->size);
+                     h2c->st0, h2c->flags, h2c->nb_streams, h2c->nb_cs, fctl_cnt, send_cnt, tree_cnt, orph_cnt, (unsigned int)h2c->dbuf->i, (unsigned int)h2c->dbuf->size, (unsigned int)h2c->mbuf->o, (unsigned int)h2c->mbuf->size);
 }
 
 /*******************************************************/
index 9fdf6621b3c3cd65c7463f45782e4b2f243a100e..30bfc6721c16e088a1b0cc271ea59fbac023a506 100644 (file)
@@ -2974,15 +2974,15 @@ static int stats_dump_full_strm_to_buffer(struct stream_interface *si, struct st
 
                chunk_appendf(&trash,
                             " wex=%s\n"
-                            "      buf=%p data=%p o=%d p=%d req.next=%d i=%d size=%d\n",
+                            "      buf=%p data=%p o=%u p=%d req.next=%d i=%u size=%u\n",
                             strm->req.wex ?
                             human_time(TICKS_TO_MS(strm->req.wex - now_ms),
                                        TICKS_TO_MS(1000)) : "<NEVER>",
                             strm->req.buf,
-                            strm->req.buf->data, strm->req.buf->o,
+                            strm->req.buf->data, (unsigned int)strm->req.buf->o,
                             (int)(strm->req.buf->p - strm->req.buf->data),
-                            strm->txn ? strm->txn->req.next : 0, strm->req.buf->i,
-                            strm->req.buf->size);
+                            strm->txn ? strm->txn->req.next : 0, (unsigned int)strm->req.buf->i,
+                            (unsigned int)strm->req.buf->size);
 
                chunk_appendf(&trash,
                             "  res=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n"
@@ -3003,15 +3003,15 @@ static int stats_dump_full_strm_to_buffer(struct stream_interface *si, struct st
 
                chunk_appendf(&trash,
                             " wex=%s\n"
-                            "      buf=%p data=%p o=%d p=%d rsp.next=%d i=%d size=%d\n",
+                            "      buf=%p data=%p o=%u p=%d rsp.next=%d i=%u size=%u\n",
                             strm->res.wex ?
                             human_time(TICKS_TO_MS(strm->res.wex - now_ms),
                                        TICKS_TO_MS(1000)) : "<NEVER>",
                             strm->res.buf,
-                            strm->res.buf->data, strm->res.buf->o,
+                            strm->res.buf->data, (unsigned int)strm->res.buf->o,
                             (int)(strm->res.buf->p - strm->res.buf->data),
-                            strm->txn ? strm->txn->rsp.next : 0, strm->res.buf->i,
-                            strm->res.buf->size);
+                            strm->txn ? strm->txn->rsp.next : 0, (unsigned int)strm->res.buf->i,
+                            (unsigned int)strm->res.buf->size);
 
                if (ci_putchk(si_ic(si), &trash) == -1) {
                        si_applet_cant_put(si);
@@ -3158,9 +3158,9 @@ static int cli_io_handler_dump_sess(struct appctx *appctx)
                                     curr_strm->task->calls);
 
                        chunk_appendf(&trash,
-                                    " rq[f=%06xh,i=%d,an=%02xh,rx=%s",
+                                    " rq[f=%06xh,i=%u,an=%02xh,rx=%s",
                                     curr_strm->req.flags,
-                                    curr_strm->req.buf->i,
+                                    (unsigned int)curr_strm->req.buf->i,
                                     curr_strm->req.analysers,
                                     curr_strm->req.rex ?
                                     human_time(TICKS_TO_MS(curr_strm->req.rex - now_ms),
@@ -3179,9 +3179,9 @@ static int cli_io_handler_dump_sess(struct appctx *appctx)
                                                TICKS_TO_MS(1000)) : "");
 
                        chunk_appendf(&trash,
-                                    " rp[f=%06xh,i=%d,an=%02xh,rx=%s",
+                                    " rp[f=%06xh,i=%u,an=%02xh,rx=%s",
                                     curr_strm->res.flags,
-                                    curr_strm->res.buf->i,
+                                    (unsigned int)curr_strm->res.buf->i,
                                     curr_strm->res.analysers,
                                     curr_strm->res.rex ?
                                     human_time(TICKS_TO_MS(curr_strm->res.rex - now_ms),