From 94ae43be363626cd9bd94da9081db3301defdc24 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 18 Jan 2023 12:17:02 +0100 Subject: [PATCH] common: Replace all assert by log_assert. -- --- common/iobuf.c | 62 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/common/iobuf.c b/common/iobuf.c index 86bb29641..ab8368b54 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -27,6 +27,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, see . + * SPDX-License-Identifier: (LGPL-3.0-or-later OR GPL-2.0-or-later) */ #include @@ -35,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -207,7 +207,7 @@ fd_cache_invalidate (const char *fname) close_cache_t cc; int rc = 0; - assert (fname); + log_assert (fname); if (DBG_IOBUF) log_debug ("fd_cache_invalidate (%s)\n", fname); @@ -370,7 +370,7 @@ fd_cache_close (const char *fname, gnupg_fd_t fp) { close_cache_t cc; - assert (fp); + log_assert (fp); if (!fname || !*fname) { #ifdef HAVE_W32_SYSTEM @@ -411,7 +411,7 @@ fd_cache_open (const char *fname, const char *mode) { close_cache_t cc; - assert (fname); + log_assert (fname); for (cc = close_cache; cc; cc = cc->next) { if (cc->fp != GNUPG_INVALID_FD && !fd_cache_strcmp (cc->fname, fname)) @@ -632,7 +632,7 @@ file_es_filter (void *opaque, int control, iobuf_t chain, byte * buf, if (control == IOBUFCTRL_UNDERFLOW) { - assert (size); /* We need a buffer. */ + log_assert (size); /* We need a buffer. */ if (a->eof_seen) { rc = -1; @@ -751,7 +751,7 @@ sock_filter (void *opaque, int control, iobuf_t chain, byte * buf, if (control == IOBUFCTRL_UNDERFLOW) { - assert (size); /* need a buffer */ + log_assert (size); /* need a buffer */ if (a->eof_seen) { rc = -1; @@ -846,7 +846,7 @@ block_filter (void *opaque, int control, iobuf_t chain, byte * buffer, size_t n = 0; p = buf; - assert (size); /* need a buffer */ + log_assert (size); /* need a buffer */ if (a->eof) /* don't read any further */ rc = -1; while (!rc && size) @@ -974,7 +974,7 @@ block_filter (void *opaque, int control, iobuf_t chain, byte * buffer, { /* the complicated openpgp scheme */ size_t blen, n, nbytes = size + a->buflen; - assert (a->buflen <= OP_MIN_PARTIAL_CHUNK); + log_assert (a->buflen <= OP_MIN_PARTIAL_CHUNK); if (nbytes < OP_MIN_PARTIAL_CHUNK) { /* not enough to write a partial block out; so we store it */ @@ -998,12 +998,12 @@ block_filter (void *opaque, int control, iobuf_t chain, byte * buffer, blen /= 2; c--; /* write the partial length header */ - assert (c <= 0x1f); /*;-) */ + log_assert (c <= 0x1f); /*;-) */ c |= 0xe0; iobuf_put (chain, c); if ((n = a->buflen)) { /* write stuff from the buffer */ - assert (n == OP_MIN_PARTIAL_CHUNK); + log_assert (n == OP_MIN_PARTIAL_CHUNK); if (iobuf_write (chain, a->buffer, n)) rc = gpg_error_from_syserror (); a->buflen = 0; @@ -1020,8 +1020,8 @@ block_filter (void *opaque, int control, iobuf_t chain, byte * buffer, /* store the rest in the buffer */ if (!rc && nbytes) { - assert (!a->buflen); - assert (nbytes < OP_MIN_PARTIAL_CHUNK); + log_assert (!a->buflen); + log_assert (nbytes < OP_MIN_PARTIAL_CHUNK); if (!a->buffer) a->buffer = xmalloc (OP_MIN_PARTIAL_CHUNK); memcpy (a->buffer, p, nbytes); @@ -1183,8 +1183,8 @@ iobuf_alloc (int use, size_t bufsize) iobuf_t a; static int number = 0; - assert (use == IOBUF_INPUT || use == IOBUF_INPUT_TEMP - || use == IOBUF_OUTPUT || use == IOBUF_OUTPUT_TEMP); + log_assert (use == IOBUF_INPUT || use == IOBUF_INPUT_TEMP + || use == IOBUF_OUTPUT || use == IOBUF_OUTPUT_TEMP); if (bufsize == 0) { log_bug ("iobuf_alloc() passed a bufsize of 0!\n"); @@ -1304,7 +1304,7 @@ iobuf_temp_with_content (const char *buffer, size_t length) int i; a = iobuf_alloc (IOBUF_INPUT_TEMP, length); - assert (length == a->d.size); + log_assert (length == a->d.size); /* memcpy (a->d.buf, buffer, length); */ for (i=0; i < length; i++) a->d.buf[i] = buffer[i]; @@ -1335,7 +1335,7 @@ do_open (const char *fname, int special_filenames, int fd; byte desc[MAX_IOBUF_DESC]; - assert (use == IOBUF_INPUT || use == IOBUF_OUTPUT); + log_assert (use == IOBUF_INPUT || use == IOBUF_OUTPUT); if (special_filenames /* NULL or '-'. */ @@ -1755,13 +1755,13 @@ iobuf_pop_filter (iobuf_t a, int (*f) (void *opaque, int control, if (a->use == IOBUF_INPUT_TEMP || a->use == IOBUF_OUTPUT_TEMP) { /* This should be the last filter in the pipeline. */ - assert (! a->chain); + log_assert (! a->chain); return 0; } if (!a->filter) { /* this is simple */ b = a->chain; - assert (b); + log_assert (b); xfree (a->d.buf); xfree (a->real_fname); memcpy (a, b, sizeof *a); @@ -1856,14 +1856,14 @@ underflow_target (iobuf_t a, int clear_pending_eof, size_t target) buffer. */ return -1; - assert (a->use == IOBUF_INPUT); + log_assert (a->use == IOBUF_INPUT); a->e_d.used = 0; /* If there is still some buffered data, then move it to the start of the buffer and try to fill the end of the buffer. (This is useful if we are called from iobuf_peek().) */ - assert (a->d.start <= a->d.len); + log_assert (a->d.start <= a->d.len); a->d.len -= a->d.start; if (a->d.len) memmove (a->d.buf, &a->d.buf[a->d.start], a->d.len); @@ -2027,7 +2027,7 @@ underflow_target (iobuf_t a, int clear_pending_eof, size_t target) } } - assert (a->d.start <= a->d.len); + log_assert (a->d.start <= a->d.len); if (a->e_d.used > 0) return 0; if (a->d.start < a->d.len) @@ -2107,7 +2107,7 @@ iobuf_readbyte (iobuf_t a) return -1; } - assert (a->d.start <= a->d.len); + log_assert (a->d.start <= a->d.len); if (a->nlimit && a->nbytes >= a->nlimit) return -1; /* forced EOF */ @@ -2119,7 +2119,7 @@ iobuf_readbyte (iobuf_t a) else if ((c = underflow (a, 1)) == -1) return -1; /* EOF */ - assert (a->d.start <= a->d.len); + log_assert (a->d.start <= a->d.len); /* Note: if underflow doesn't return EOF, then it returns the first byte that was read and advances a->d.start appropriately. */ @@ -2244,8 +2244,8 @@ iobuf_peek (iobuf_t a, byte * buf, unsigned buflen) { int n = 0; - assert (buflen > 0); - assert (a->use == IOBUF_INPUT || a->use == IOBUF_INPUT_TEMP); + log_assert (buflen > 0); + log_assert (a->use == IOBUF_INPUT || a->use == IOBUF_INPUT_TEMP); if (buflen > a->d.size) /* We can't peek more than we can buffer. */ @@ -2261,7 +2261,7 @@ iobuf_peek (iobuf_t a, byte * buf, unsigned buflen) /* Underflow consumes the first character (it's the return value). unget() it by resetting the "file position". */ - assert (a->d.start == 1); + log_assert (a->d.start == 1); a->d.start = 0; } @@ -2296,7 +2296,7 @@ iobuf_writebyte (iobuf_t a, unsigned int c) if ((rc=filter_flush (a))) return rc; - assert (a->d.len < a->d.size); + log_assert (a->d.len < a->d.size); a->d.buf[a->d.len++] = c; return 0; } @@ -2397,8 +2397,8 @@ iobuf_writestr (iobuf_t a, const char *buf) int iobuf_write_temp (iobuf_t dest, iobuf_t source) { - assert (source->use == IOBUF_OUTPUT || source->use == IOBUF_OUTPUT_TEMP); - assert (dest->use == IOBUF_OUTPUT || dest->use == IOBUF_OUTPUT_TEMP); + log_assert (source->use == IOBUF_OUTPUT || source->use == IOBUF_OUTPUT_TEMP); + log_assert (dest->use == IOBUF_OUTPUT || dest->use == IOBUF_OUTPUT_TEMP); iobuf_flush_temp (source); return iobuf_write (dest, source->d.buf, source->d.len); @@ -2782,7 +2782,7 @@ iobuf_read_line (iobuf_t a, byte ** addr_of_buffer, NUL character in the buffer. This requires at least 2 bytes. We don't complicate the code by handling the stupid corner case, but simply assert that it can't happen. */ - assert (!buffer || length >= 2 || maxlen >= 2); + log_assert (!buffer || length >= 2 || maxlen >= 2); if (!buffer || length <= 1) /* must allocate a new buffer */ @@ -2853,7 +2853,7 @@ iobuf_read_line (iobuf_t a, byte ** addr_of_buffer, /* p is pointing at the last byte in the buffer. We always terminate the line with "\n\0" so overwrite the previous byte with a \n. */ - assert (p > buffer); + log_assert (p > buffer); p[-1] = '\n'; /* Indicate truncation. */