Browse Source

[core] uint32_t for struct buffer sizes

personal/stbuehler/ci-build
Glenn Strauss 2 years ago
parent
commit
10d71279ae
  1. 2
      src/buffer.c
  2. 16
      src/buffer.h
  3. 15
      src/connections.c

2
src/buffer.c

@ -128,7 +128,7 @@ char* buffer_string_prepare_append(buffer *b, size_t size) {
: buffer_string_prepare_append_resize(b, size);
}
void buffer_string_set_length(buffer *b, size_t len) {
void buffer_string_set_length(buffer *b, uint32_t len) {
force_assert(NULL != b);
if (len >= b->size) buffer_realloc(b, len);

16
src/buffer.h

@ -19,9 +19,9 @@ typedef struct {
char *ptr;
/* "used" includes a terminating 0 */
size_t used;
uint32_t used;
/* size of allocated buffer at *ptr */
size_t size;
uint32_t size;
} buffer;
/* create new buffer; either empty or copy given data */
@ -63,7 +63,7 @@ void buffer_commit(buffer *b, size_t size);
* - does not modify the string data apart from terminating zero
* - reallocates the buffer iff needed
*/
void buffer_string_set_length(buffer *b, size_t len);
void buffer_string_set_length(buffer *b, uint32_t len);
/* clear buffer
* - invalidate buffer contents
@ -191,10 +191,10 @@ static inline int light_isalnum(int c) {
__attribute_pure__
static inline size_t buffer_string_length(const buffer *b); /* buffer string length without terminating 0 */
static inline uint32_t buffer_string_length(const buffer *b); /* buffer string length without terminating 0 */
__attribute_pure__
static inline size_t buffer_string_space(const buffer *b); /* maximum length of string that can be stored without reallocating */
static inline uint32_t buffer_string_space(const buffer *b); /* maximum length of string that can be stored without reallocating */
static inline void buffer_append_slash(buffer *b); /* append '/' no non-empty strings not ending in '/' */
void buffer_append_path_len(buffer *b, const char *a, size_t alen); /* join strings with '/', if '/' not present */
@ -227,11 +227,11 @@ static inline int buffer_string_is_empty(const buffer *b) {
return NULL == b || b->used < 2;
}
static inline size_t buffer_string_length(const buffer *b) {
static inline uint32_t buffer_string_length(const buffer *b) {
return NULL != b && 0 != b->used ? b->used - 1 : 0;
}
static inline size_t buffer_string_space(const buffer *b) {
static inline uint32_t buffer_string_space(const buffer *b) {
return NULL != b && b->size ? b->size - (b->used | (0 == b->used)) : 0;
}
@ -244,7 +244,7 @@ static inline void buffer_append_string_buffer(buffer *b, const buffer *src) {
}
static inline void buffer_append_slash(buffer *b) {
size_t len = buffer_string_length(b);
uint32_t len = buffer_string_length(b);
if (len > 0 && '/' != b->ptr[len-1]) BUFFER_APPEND_STRING_CONST(b, "/");
}

15
src/connections.c

@ -724,19 +724,20 @@ static chunk * connection_read_header_more(connection *con, chunkqueue *cq, chun
/* detect if data is added to chunk */
c = cq->first;
return
(NULL != c && olen < buffer_string_length(c->mem) - c->offset) ? c : NULL;
return (c && (size_t)c->offset + olen < buffer_string_length(c->mem))
? c
: NULL;
}
__attribute_hot__
static uint32_t connection_read_header_hoff(const char *n, const size_t clen, unsigned short hoff[8192]) {
size_t hlen = 0;
static uint32_t connection_read_header_hoff(const char *n, const uint32_t clen, unsigned short hoff[8192]) {
uint32_t hlen = 0;
for (const char *b; (n = memchr((b = n),'\n',clen-hlen)); ++n) {
size_t x = (size_t)(n - b + 1);
uint32_t x = (uint32_t)(n - b + 1);
hlen += x;
if (x <= 2 && (x == 1 || n[-1] == '\r')) {
hoff[hoff[0]+1] = hlen;
return hlen <= UINT32_MAX ? (uint32_t)hlen : 0;
return hlen;
}
if (++hoff[0] >= /*sizeof(hoff)/sizeof(hoff[0])-1*/ 8192-1) break;
hoff[hoff[0]] = hlen;
@ -768,7 +769,7 @@ static int connection_handle_read_state(server * const srv, connection * const c
chunkqueue * const cq = con->read_queue;
chunk *c = cq->first;
size_t clen = 0;
uint32_t clen = 0;
unsigned short hoff[8192]; /* max num header lines + 3; 16k on stack */
do {

Loading…
Cancel
Save