-/* $OpenBSD: imsg-buffer.c,v 1.14 2022/04/23 08:57:52 tobias Exp $ */
+/* $OpenBSD: imsg-buffer.c,v 1.15 2023/05/23 12:41:28 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
{
struct ibuf *buf;
+ if (len == 0) {
+ errno = EINVAL;
+ return (NULL);
+ }
if ((buf = calloc(1, sizeof(struct ibuf))) == NULL)
return (NULL);
- if ((buf->buf = malloc(len)) == NULL) {
+ if ((buf->buf = calloc(len, 1)) == NULL) {
free(buf);
return (NULL);
}
{
struct ibuf *buf;
- if (max < len)
+ if (max < len) {
+ errno = EINVAL;
return (NULL);
+ }
- if ((buf = ibuf_open(len)) == NULL)
+ if ((buf = calloc(1, sizeof(struct ibuf))) == NULL)
return (NULL);
-
- if (max > 0)
- buf->max = max;
+ if (len > 0) {
+ if ((buf->buf = calloc(len, 1)) == NULL) {
+ free(buf);
+ return (NULL);
+ }
+ }
+ buf->size = len;
+ buf->max = max;
+ buf->fd = -1;
return (buf);
}
b = buf->buf + buf->wpos;
buf->wpos += len;
+ memset(b, 0, len);
return (b);
}