]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: chunk: remove impossible tests on negative chunk->data
authorWilly Tarreau <w@1wt.eu>
Wed, 22 Aug 2018 02:59:48 +0000 (04:59 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 22 Aug 2018 03:28:32 +0000 (05:28 +0200)
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.

include/common/chunk.h
src/chunk.c

index a127f9af410ceb017af98f23e0d9a92c288e2841..383e15736f18629781442435eef4b1762fef6349 100644 (file)
@@ -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)
index 7e90ee6e2e8388d1864d177c14934cbda11c306f..303d3fdc9575313b02102c4f356dd37cb34cd243 100644 (file)
@@ -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++) {