MINOR: buffer: switch buffer sizes and offsets to size_t

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.
This commit is contained in:
Willy Tarreau 2018-07-18 10:07:58 +02:00
parent 41806d1c52
commit 506a29ac6e
6 changed files with 25 additions and 23 deletions

View File

@ -28,13 +28,15 @@
#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 */
};

View 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");

View 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;

View 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;
}
}

View 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);
}
/*******************************************************/

View 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),