From: Willy Tarreau Date: Wed, 22 Aug 2018 02:59:48 +0000 (+0200) Subject: MINOR: chunk: remove impossible tests on negative chunk->data X-Git-Tag: v1.9-dev2~123 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bba81563cf5e5fcf31920a57772d3aef9e983118;p=thirdparty%2Fhaproxy.git MINOR: chunk: remove impossible tests on negative chunk->data Since commit 843b7cb ("MEDIUM: chunks: make the chunk struct's fields match the buffer struct") a chunk length is unsigned so we can remove negative size checks. --- diff --git a/include/common/chunk.h b/include/common/chunk.h index a127f9af41..383e15736f 100644 --- a/include/common/chunk.h +++ b/include/common/chunk.h @@ -117,7 +117,7 @@ static inline int chunk_memcpy(struct buffer *chk, const char *src, static inline int chunk_memcat(struct buffer *chk, const char *src, size_t len) { - if (unlikely(chk->data < 0 || chk->data + len >= chk->size)) + if (unlikely(chk->data + len >= chk->size)) return 0; memcpy(chk->area + chk->data, src, len); @@ -152,7 +152,7 @@ static inline int chunk_strcat(struct buffer *chk, const char *str) len = strlen(str); - if (unlikely(chk->data < 0 || chk->data + len >= chk->size)) + if (unlikely(chk->data + len >= chk->size)) return 0; memcpy(chk->area + chk->data, str, len + 1); @@ -165,7 +165,7 @@ static inline int chunk_strcat(struct buffer *chk, const char *str) */ static inline int chunk_strncat(struct buffer *chk, const char *str, int nb) { - if (unlikely(chk->data < 0 || chk->data + nb >= chk->size)) + if (unlikely(chk->data + nb >= chk->size)) return 0; memcpy(chk->area + chk->data, str, nb); @@ -187,7 +187,7 @@ static inline int chunk_strncat(struct buffer *chk, const char *str, int nb) */ static inline char *chunk_newstr(struct buffer *chk) { - if (chk->data < 0 || chk->data + 1 >= chk->size) + if (chk->data + 1 >= chk->size) return NULL; chk->area[chk->data++] = 0; @@ -219,7 +219,7 @@ static inline void chunk_destroy(struct buffer *chk) */ static inline char *chunk_dup(struct buffer *dst, const struct buffer *src) { - if (!dst || !src || src->data < 0 || !src->area) + if (!dst || !src || !src->area) return NULL; if (dst->size) diff --git a/src/chunk.c b/src/chunk.c index 7e90ee6e2e..303d3fdc95 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -167,7 +167,7 @@ int chunk_appendf(struct buffer *chk, const char *fmt, ...) va_list argp; int ret; - if (chk->data < 0 || !chk->area || !chk->size) + if (!chk->area || !chk->size) return 0; va_start(argp, fmt); @@ -193,9 +193,6 @@ int chunk_htmlencode(struct buffer *dst, struct buffer *src) int olen, free; char c; - if (dst->data < 0) - return dst->data; - olen = dst->data; for (i = 0; i < src->data; i++) { @@ -238,9 +235,6 @@ int chunk_asciiencode(struct buffer *dst, struct buffer *src, char qc) int olen, free; char c; - if (dst->data < 0) - return dst->data; - olen = dst->data; for (i = 0; i < src->data; i++) {