diff options
author | tijl <tijl@FreeBSD.org> | 2014-06-20 07:32:03 +0000 |
---|---|---|
committer | tijl <tijl@FreeBSD.org> | 2014-06-20 07:32:03 +0000 |
commit | de4e2206d57bda2268e6b69f09b86ff63cc71f8e (patch) | |
tree | 60af671abf1bc0d1bc97daa15754adcb118b899b /lib/libc/iconv | |
parent | 7944ea7242fccf98384460100e2b5e384628fa89 (diff) | |
download | FreeBSD-src-de4e2206d57bda2268e6b69f09b86ff63cc71f8e.zip FreeBSD-src-de4e2206d57bda2268e6b69f09b86ff63cc71f8e.tar.gz |
MFC r267436-267439:
- Replace malloc+memset with calloc.
- iconv_open(3): initialise ci_ilseq_invalid field of _citrus_iconv_shared
struct after allocation with malloc.
- iconvlist(3): reduce a memory leak by copying strings only once.
- iconv(1):
- Make invalids variable local to do_conv such that it prints the number
of invalid characters of the current file instead of an accumulated
value.
- Make do_conv return an error when invalid characters have been found.
Return EXIT_FAILURE from main if any file contained invalid characters.
This matches the behaviour of GNU iconv.
- Mark usage with __dead2 attribute.
- Make the long_options array const.
Tested by: Pavel Timofeev <timp87@gmail.com>
Diffstat (limited to 'lib/libc/iconv')
-rw-r--r-- | lib/libc/iconv/bsd_iconv.c | 5 | ||||
-rw-r--r-- | lib/libc/iconv/citrus_db_factory.c | 4 | ||||
-rw-r--r-- | lib/libc/iconv/citrus_iconv.c | 3 |
3 files changed, 5 insertions, 7 deletions
diff --git a/lib/libc/iconv/bsd_iconv.c b/lib/libc/iconv/bsd_iconv.c index 40a1a4e..f764886 100644 --- a/lib/libc/iconv/bsd_iconv.c +++ b/lib/libc/iconv/bsd_iconv.c @@ -83,6 +83,7 @@ __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); @@ -223,7 +224,7 @@ __bsd_iconvlist(int (*do_one) (unsigned int, const char * const *, return; } strlcpy(curkey, list[i], slashpos - list[i] + 1); - names[j++] = strdup(curkey); + names[j++] = curkey; for (; (i < sz) && (memcmp(curkey, list[i], strlen(curkey)) == 0); i++) { slashpos = strchr(list[i], '/'); curitem = (char *)malloc(strlen(slashpos) + 1); @@ -235,7 +236,7 @@ __bsd_iconvlist(int (*do_one) (unsigned int, const char * const *, if (strcmp(curkey, curitem) == 0) { continue; } - names[j++] = strdup(curitem); + names[j++] = curitem; } np = (const char * const *)names; do_one(j, np, data); diff --git a/lib/libc/iconv/citrus_db_factory.c b/lib/libc/iconv/citrus_db_factory.c index e9823ab..691fe4e 100644 --- a/lib/libc/iconv/citrus_db_factory.c +++ b/lib/libc/iconv/citrus_db_factory.c @@ -270,11 +270,9 @@ _citrus_db_factory_serialize(struct _citrus_db_factory *df, const char *magic, return (0); } /* allocate hash table */ - depp = malloc(sizeof(*depp) * df->df_num_entries); + depp = calloc(df->df_num_entries, sizeof(*depp)); if (depp == NULL) return (-1); - for (i = 0; i < df->df_num_entries; i++) - depp[i] = NULL; /* step1: store the entries which are not conflicting */ STAILQ_FOREACH(de, &df->df_entries, de_entry) { diff --git a/lib/libc/iconv/citrus_iconv.c b/lib/libc/iconv/citrus_iconv.c index df2ed73..5c8bf49 100644 --- a/lib/libc/iconv/citrus_iconv.c +++ b/lib/libc/iconv/citrus_iconv.c @@ -344,9 +344,8 @@ const char { char *buf; - if ((buf = malloc((size_t)PATH_MAX)) == NULL) + if ((buf = calloc((size_t)PATH_MAX, sizeof(*buf))) == NULL) return (NULL); - memset((void *)buf, 0, (size_t)PATH_MAX); _citrus_esdb_alias(name, buf, (size_t)PATH_MAX); return (buf); } |