diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2023-02-10 15:27:06 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2023-02-10 15:27:06 +0100 |
commit | 7501bff8432444b7ae8e7f3d9289c0d61f3f0b64 (patch) | |
tree | bd53603f464c3747e897a8996158a0fef7b41bc3 /src/mc.c | |
parent | 0f124df68d87c9073f76efeff1a901a69b1f3e13 (diff) | |
parent | 9e9336185f86bd97ff22f54e4d561c2cccccecf5 (diff) |
Merge branch 'release/debian/4.10-1'debian/4.10-1
Diffstat (limited to 'src/mc.c')
-rw-r--r-- | src/mc.c | 35 |
1 files changed, 25 insertions, 10 deletions
@@ -8,6 +8,7 @@ * either version 2.1 or (at your option) any later version. */ #include <stddef.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -20,10 +21,12 @@ static __inline__ size_t __HXmc_request(size_t len) return sizeof(struct memcont) + len + 1; } -static __inline__ void HXmc_check(const struct memcont *c) +static __inline__ int HXmc_check(const struct memcont *c) { - if (c->id != HXMC_IDENT) + int err = c->id != HXMC_IDENT; + if (err != 0) fprintf(stderr, "libHX-mc error: not a hxmc object!\n"); + return err; } static __inline__ struct memcont *HXmc_base(const hxmc_t *p) @@ -61,7 +64,8 @@ EXPORT_SYMBOL hxmc_t *HXmc_memcpy(hxmc_t **vp, const void *ptr, size_t len) struct memcont *ctx; if (*vp != NULL) { ctx = HXmc_base(*vp); - HXmc_check(ctx); + if (HXmc_check(ctx) != 0) + return nullptr; if (ctx->alloc < len) { ctx = realloc(ctx, __HXmc_request(len)); if (ctx == NULL) @@ -79,11 +83,13 @@ EXPORT_SYMBOL hxmc_t *HXmc_memcpy(hxmc_t **vp, const void *ptr, size_t len) if (ptr == NULL) { ctx->length = 0; ctx->data[0] = '\0'; + // coverity[leaked_storage] return *vp = ctx->data; } memcpy(ctx->data, ptr, ctx->length = len); ctx->data[len] = '\0'; + // coverity[leaked_storage] return *vp = ctx->data; } @@ -94,7 +100,8 @@ EXPORT_SYMBOL size_t HXmc_length(const hxmc_t *vp) if (vp == NULL) return 0; ctx = HXmc_base(vp); - HXmc_check(ctx); + if (HXmc_check(ctx) != 0) + return SIZE_MAX; return ctx->length; } @@ -113,7 +120,8 @@ EXPORT_SYMBOL hxmc_t *HXmc_trunc(hxmc_t **vp, size_t len) { struct memcont *ctx = HXmc_base(*vp); - HXmc_check(ctx); + if (HXmc_check(ctx) != 0) + return nullptr; if (len > ctx->alloc) { ctx = realloc(ctx, __HXmc_request(len)); if (ctx == NULL) @@ -123,6 +131,7 @@ EXPORT_SYMBOL hxmc_t *HXmc_trunc(hxmc_t **vp, size_t len) ctx->data[len] = '\0'; ctx->length = len; } + // coverity[leaked_storage] return *vp = ctx->data; } @@ -138,7 +147,8 @@ EXPORT_SYMBOL hxmc_t *HXmc_memcat(hxmc_t **vp, const void *ptr, size_t len) struct memcont *ctx = HXmc_base(*vp); size_t nl = ctx->length + len; - HXmc_check(ctx); + if (HXmc_check(ctx) != 0) + return nullptr; if (nl > ctx->alloc) { ctx = realloc(ctx, __HXmc_request(nl)); if (ctx == NULL) @@ -146,11 +156,13 @@ EXPORT_SYMBOL hxmc_t *HXmc_memcat(hxmc_t **vp, const void *ptr, size_t len) ctx->alloc = nl; } if (ptr == NULL) + // coverity[leaked_storage] return *vp = ctx->data; memcpy(ctx->data + ctx->length, ptr, len); ctx->length = nl; ctx->data[nl] = '\0'; + // coverity[leaked_storage] return *vp = ctx->data; } @@ -186,7 +198,8 @@ EXPORT_SYMBOL hxmc_t *HXmc_memins(hxmc_t **vp, size_t pos, const void *ptr, struct memcont *ctx = HXmc_base(*vp); size_t nl = ctx->length + len; - HXmc_check(ctx); + if (HXmc_check(ctx) != 0) + return nullptr; if (ctx->alloc < nl) { ctx = realloc(ctx, __HXmc_request(nl)); if (ctx == NULL) @@ -200,14 +213,15 @@ EXPORT_SYMBOL hxmc_t *HXmc_memins(hxmc_t **vp, size_t pos, const void *ptr, memcpy(ctx->data + pos, ptr, len); ctx->length += len; ctx->data[ctx->length] = '\0'; + // coverity[leaked_storage] return *vp = ctx->data; } EXPORT_SYMBOL hxmc_t *HXmc_memdel(hxmc_t *vp, size_t pos, size_t len) { struct memcont *ctx = HXmc_base(vp); - HXmc_check(ctx); - + if (HXmc_check(ctx) != 0) + return nullptr; if (pos + len > ctx->length) len = ctx->length - pos; @@ -224,7 +238,8 @@ EXPORT_SYMBOL void HXmc_free(hxmc_t *vp) if (vp == NULL) return; ctx = HXmc_base(vp); - HXmc_check(ctx); + if (HXmc_check(ctx) != 0) + return; free(ctx); } |