git: 939199a2b5e8 - main - libc: iconv: zero out cv_shared on allocation
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 23 Aug 2023 03:41:18 UTC
The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=939199a2b5e8b5c793b9481401e468d19fda65ec commit 939199a2b5e8b5c793b9481401e468d19fda65ec Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2023-08-23 03:40:45 +0000 Commit: Kyle Evans <kevans@FreeBSD.org> CommitDate: 2023-08-23 03:40:45 +0000 libc: iconv: zero out cv_shared on allocation Right now we have to zero-initialize most fields in the varius callers, but this is a little error prone. Simplify it by zeroing it out upon allocation instead, drop the other redundant initialization. Reviewed by: markj Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D41546 --- lib/libc/iconv/bsd_iconv.c | 2 -- lib/libc/iconv/citrus_iconv.c | 5 +---- lib/libc/locale/cXXrtomb_iconv.h | 2 -- lib/libc/locale/mbrtocXX_iconv.h | 2 -- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/libc/iconv/bsd_iconv.c b/lib/libc/iconv/bsd_iconv.c index 744af30212a1..fe2491d665dd 100644 --- a/lib/libc/iconv/bsd_iconv.c +++ b/lib/libc/iconv/bsd_iconv.c @@ -70,8 +70,6 @@ __bsd___iconv_open(const char *out, const char *in, struct _citrus_iconv *handle } handle->cv_shared->ci_discard_ilseq = strcasestr(out, "//IGNORE"); - handle->cv_shared->ci_ilseq_invalid = false; - handle->cv_shared->ci_hooks = NULL; return ((iconv_t)(void *)handle); } diff --git a/lib/libc/iconv/citrus_iconv.c b/lib/libc/iconv/citrus_iconv.c index ecb176c46063..a2ff7b5177c8 100644 --- a/lib/libc/iconv/citrus_iconv.c +++ b/lib/libc/iconv/citrus_iconv.c @@ -140,14 +140,11 @@ open_shared(struct _citrus_iconv_shared * __restrict * __restrict rci, /* initialize iconv handle */ len_convname = strlen(convname); - ci = malloc(sizeof(*ci) + len_convname + 1); + ci = calloc(1, sizeof(*ci) + len_convname + 1); if (!ci) { ret = errno; goto err; } - ci->ci_module = NULL; - ci->ci_ops = NULL; - ci->ci_closure = NULL; ci->ci_convname = (void *)&ci[1]; memcpy(ci->ci_convname, convname, len_convname + 1); diff --git a/lib/libc/locale/cXXrtomb_iconv.h b/lib/libc/locale/cXXrtomb_iconv.h index 8f123e85c66d..cca2c1f160d4 100644 --- a/lib/libc/locale/cXXrtomb_iconv.h +++ b/lib/libc/locale/cXXrtomb_iconv.h @@ -75,8 +75,6 @@ cXXrtomb_l(char * __restrict s, charXX_t c, mbstate_t * __restrict ps, errno = EINVAL; return (-1); } - handle->cv_shared->ci_discard_ilseq = false; - handle->cv_shared->ci_hooks = NULL; cs->srcbuf_len = 0; cs->initialized = true; if (s == NULL) diff --git a/lib/libc/locale/mbrtocXX_iconv.h b/lib/libc/locale/mbrtocXX_iconv.h index 22b8a7d4031c..c3c832149617 100644 --- a/lib/libc/locale/mbrtocXX_iconv.h +++ b/lib/libc/locale/mbrtocXX_iconv.h @@ -78,8 +78,6 @@ mbrtocXX_l(charXX_t * __restrict pc, const char * __restrict s, size_t n, errno = EINVAL; return (-1); } - handle->cv_shared->ci_discard_ilseq = false; - handle->cv_shared->ci_hooks = NULL; cs->srcbuf_len = cs->dstbuf_len = 0; cs->initialized = true; if (s == NULL)