* [PATCH 1/4] libc/iconv: Detect CES handler loading failure
@ 2020-07-09 23:58 Keith Packard
2020-07-09 23:58 ` [PATCH 2/4] libc/iconv: Remove unneeded pointer var for _iconv_aliases Keith Packard
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Keith Packard @ 2020-07-09 23:58 UTC (permalink / raw)
To: newlib
Fix the code checking for character set loading failure so that
it checks the return value from the init function.
Signed-off-by: Keith Packard <keithp@keithp.com>
---
newlib/libc/iconv/ces/euc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/newlib/libc/iconv/ces/euc.c b/newlib/libc/iconv/ces/euc.c
index 29d36f941..ebd7091b0 100644
--- a/newlib/libc/iconv/ces/euc.c
+++ b/newlib/libc/iconv/ces/euc.c
@@ -306,7 +306,7 @@ ok:
data->data[i] = _iconv_to_ucs_ces_handlers_table.init (
rptr,
data->desc[i].csname);
- if (data->data == NULL)
+ if (data->data[i] == NULL)
goto error;
}
--
2.27.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/4] libc/iconv: Remove unneeded pointer var for _iconv_aliases
2020-07-09 23:58 [PATCH 1/4] libc/iconv: Detect CES handler loading failure Keith Packard
@ 2020-07-09 23:58 ` Keith Packard
2020-07-09 23:58 ` [PATCH 3/4] libc/iconv: find_alias was mis-computing remaining alias table length Keith Packard
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Keith Packard @ 2020-07-09 23:58 UTC (permalink / raw)
To: newlib
The pointer value for the iconv alias data never changes, so get rid
of the pointer and make it an array instead.
Signed-off-by: Keith Packard <keithp@keithp.com>
---
newlib/libc/iconv/lib/aliasesbi.c | 5 ++---
newlib/libc/iconv/lib/local.h | 4 +---
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/newlib/libc/iconv/lib/aliasesbi.c b/newlib/libc/iconv/lib/aliasesbi.c
index dfd7090d0..83b6fd003 100644
--- a/newlib/libc/iconv/lib/aliasesbi.c
+++ b/newlib/libc/iconv/lib/aliasesbi.c
@@ -5,8 +5,8 @@
#include <_ansi.h>
#include "encnames.h"
-const char *
-_iconv_aliases =
+const char
+_iconv_aliases[] =
{
#if defined (_ICONV_FROM_ENCODING_BIG5) \
|| defined (_ICONV_TO_ENCODING_BIG5)
@@ -210,4 +210,3 @@ _iconv_aliases =
#endif
""
};
-
diff --git a/newlib/libc/iconv/lib/local.h b/newlib/libc/iconv/lib/local.h
index bd9dcddca..2d3a16969 100644
--- a/newlib/libc/iconv/lib/local.h
+++ b/newlib/libc/iconv/lib/local.h
@@ -57,10 +57,8 @@ typedef __uint16_t ucs2_t;
/* 32-bit UCS-4 type */
typedef __uint32_t ucs4_t;
-
/* The list of built-in encoding names and aliases */
-extern const char *
-_iconv_aliases;
+extern const char _iconv_aliases[];
#endif /* !__ICONV_LIB_LOCAL_H__ */
--
2.27.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/4] libc/iconv: find_alias was mis-computing remaining alias table length
2020-07-09 23:58 [PATCH 1/4] libc/iconv: Detect CES handler loading failure Keith Packard
2020-07-09 23:58 ` [PATCH 2/4] libc/iconv: Remove unneeded pointer var for _iconv_aliases Keith Packard
@ 2020-07-09 23:58 ` Keith Packard
2020-07-09 23:58 ` [PATCH 4/4] testsuite: Fix iconv tests to use new encoding config defines Keith Packard
2020-07-10 10:05 ` [PATCH 1/4] libc/iconv: Detect CES handler loading failure Corinna Vinschen
3 siblings, 0 replies; 6+ messages in thread
From: Keith Packard @ 2020-07-09 23:58 UTC (permalink / raw)
To: newlib
This caused the strnstr to walk off the end of the alias array and
fetch invalid data. Instead of attempting to update 'len', just
re-compute it based on the table end pointer that is already known.
Signed-off-by: Keith Packard <keithp@keithp.com>
---
newlib/libc/iconv/lib/aliasesi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/newlib/libc/iconv/lib/aliasesi.c b/newlib/libc/iconv/lib/aliasesi.c
index d04cebb57..ef5ce4109 100644
--- a/newlib/libc/iconv/lib/aliasesi.c
+++ b/newlib/libc/iconv/lib/aliasesi.c
@@ -115,7 +115,7 @@ search_again:
&& (p+l == table_end || isspace (*(p+l)) || *(p+l) == '\n')))
{
ptable = p + l;
- len -= table - p;
+ len = table_end - ptable;
goto search_again;
}
--
2.27.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/4] testsuite: Fix iconv tests to use new encoding config defines
2020-07-09 23:58 [PATCH 1/4] libc/iconv: Detect CES handler loading failure Keith Packard
2020-07-09 23:58 ` [PATCH 2/4] libc/iconv: Remove unneeded pointer var for _iconv_aliases Keith Packard
2020-07-09 23:58 ` [PATCH 3/4] libc/iconv: find_alias was mis-computing remaining alias table length Keith Packard
@ 2020-07-09 23:58 ` Keith Packard
2020-07-10 10:05 ` [PATCH 1/4] libc/iconv: Detect CES handler loading failure Corinna Vinschen
3 siblings, 0 replies; 6+ messages in thread
From: Keith Packard @ 2020-07-09 23:58 UTC (permalink / raw)
To: newlib
_ICONV_CONVERTER -> ICONV_FROM_ENCODING. It's not perfect, as the
library can support different from/to encodings now, but at least in
the default configurations the tests now work.
Signed-off-by: Keith Packard <keithp@keithp.com>
---
newlib/testsuite/newlib.iconv/iconvjp.c | 61 ++++++++++++-------------
newlib/testsuite/newlib.iconv/iconvnm.c | 8 ++--
newlib/testsuite/newlib.iconv/iconvru.c | 26 +++++------
3 files changed, 47 insertions(+), 48 deletions(-)
diff --git a/newlib/testsuite/newlib.iconv/iconvjp.c b/newlib/testsuite/newlib.iconv/iconvjp.c
index 2022851a3..6c85399c7 100644
--- a/newlib/testsuite/newlib.iconv/iconvjp.c
+++ b/newlib/testsuite/newlib.iconv/iconvjp.c
@@ -31,12 +31,12 @@
#ifdef _ICONV_ENABLED
-#if defined(_ICONV_CONVERTER_UTF_8) || \
- defined(_ICONV_CONVERTER_EUC_JP) || \
- defined(_ICONV_CONVERTER_SHIFT_JIS) || \
- defined(_ICONV_CONVERTER_UCS_2_INTERNAL)
+#if defined(_ICONV_FROM_ENCODING_UTF_8) || \
+ defined(_ICONV_FROM_ENCODING_EUC_JP) || \
+ defined(_ICONV_FROM_ENCODING_SHIFT_JIS) || \
+ defined(_ICONV_FROM_ENCODING_UCS_2_INTERNAL)
-#ifdef _ICONV_CONVERTER_UTF_8
+#ifdef _ICONV_FROM_ENCODING_UTF_8
char utf8[] =
{
0xe8,0x89,0xb2,0xe3,0x80,0x85,0xe3,0x83,0x86,0xe3,
@@ -227,9 +227,9 @@ char utf8[] =
0x95,0xe3,0x82,0xa9,0xe3,0x83,0xbc,0xe3,0x83,0x9e,
0xe3,0x83,0x83,0xe3,0x83,0x88,0x0d,0xa
};
-#endif /* ifdef _ICONV_CONVERTER_UTF_8 */
-
-#ifdef _ICONV_CONVERTER_EUC_JP
+#endif /* ifdef _ICONV_FROM_ENCODING_UTF_8 */
+
+#ifdef _ICONV_FROM_ENCODING_EUC_JP
char euc_jp[] =
{
0xbf,0xa7,0xa1,0xb9,0xa5,0xc6,0xa5,0xad,0xa5,0xb9,
@@ -394,10 +394,10 @@ char utf8[] =
0xa5,0xca,0xa5,0xea,0x49,0x49,0xa5,0xd5,0xa5,0xa9,
0xa1,0xbc,0xa5,0xde,0xa5,0xc3,0xa5,0xc8,0x0d,0x0a
};
-#endif /* #ifdef _ICONV_CONVERTER_EUC_JP */
+#endif /* #ifdef _ICONV_FROM_ENCODING_EUC_JP */
-#ifdef _ICONV_CONVERTER_SHIFT_JIS
-char shift_jis[] =
+#ifdef _ICONV_FROM_ENCODING_SHIFT_JIS
+char shift_jis[] =
{
0x90,0x46,0x81,0x58,0x83,0x65,0x83,0x4c,0x83,0x58,
0x83,0x67,0x83,0x74,0x83,0x40,0x83,0x43,0x83,0x8b,
@@ -561,9 +561,9 @@ char shift_jis[] =
0x83,0x69,0x83,0x8a,0x49,0x49,0x83,0x74,0x83,0x48,
0x81,0x5b,0x83,0x7d,0x83,0x62,0x83,0x67,0x0d,0x0a
};
-#endif /* _ICONV_CONVERTER_SHIFT_JIS */
+#endif /* _ICONV_FROM_ENCODING_SHIFT_JIS */
-#ifdef _ICONV_CONVERTER_UCS_2_INTERNAL
+#ifdef _ICONV_FROM_ENCODING_UCS_2_INTERNAL
short ucs2[] =
{
0x8272,0x3005,0x30c6,0x30ad,0x30b9,
@@ -849,18 +849,18 @@ struct iconv_data
#define CONVERSIONS 4
-struct iconv_data data[] =
+struct iconv_data data[] =
{
-#ifdef _ICONV_CONVERTER_EUC_JP
+#if defined(_ICONV_FROM_ENCODING_EUC_JP) && defined(_ICONV_TO_ENCODING_EUC_JP)
{sizeof(euc_jp), "EUC-JP", (char *)euc_jp},
#endif
-#ifdef _ICONV_CONVERTER_SHIFT_JIS
+#if defined(_ICONV_FROM_ENCODING_SHIFT_JIS) && defined(_ICONV_TO_ENCODING_SHIFT_JIS)
{sizeof(shift_jis), "SHIFT-JIS", (char *)shift_jis},
#endif
-#ifdef _ICONV_CONVERTER_UTF_8
+#if defined(_ICONV_FROM_ENCODING_UTF_8) && defined(_ICONV_TO_ENCODING_UTF_8)
{sizeof(utf8), "UTF-8", (char *)utf8},
#endif
-#ifdef _ICONV_CONVERTER_UCS_2_INTERNAL
+#if defined(_ICONV_FROM_ENCODING_UCS_2_INTERNAL) && defined(_ICONV_TO_ENCODING_UCS_2_INTERNAL)
{sizeof(ucs2), "UCS-2-INTERNAL", (char *)ucs2},
#endif
{0, NULL, NULL}
@@ -881,7 +881,7 @@ int main(int argc, char **argv)
int conversions = sizeof(data)/sizeof(struct iconv_data) - 1;
puts("JP iconv test");
-
+
for (i = 0; i < conversions; i++)
{
for (j = 0; j < conversions; j++)
@@ -895,7 +895,7 @@ int main(int argc, char **argv)
}
}
}
-
+
d = 0;
for (i = 0; i < conversions; i++)
{
@@ -911,8 +911,8 @@ int main(int argc, char **argv)
perror("Can't reset shift state");
CHECK(ERROR);
}
-
- n = iconv(descs[d++], (const char **)&(inbuf), &inbytes,
+
+ n = iconv(descs[d++], (const char **)&(inbuf), &inbytes,
(char **)&outbuf, &outbytes);
if (n == (size_t)-1)
{
@@ -921,7 +921,7 @@ int main(int argc, char **argv)
perror("");
CHECK(ERROR);
}
-
+
if (data[j].len != OUTBUF_LEN - outbytes)
{
printf("Conversion from %s to %s FAILED",
@@ -930,7 +930,7 @@ int main(int argc, char **argv)
OUTBUF_LEN - outbytes, data[j].len);
CHECK(ERROR);
}
-
+
for (k = 0; k < data[j].len; k++)
{
if (ob[k] != data[j].data[k])
@@ -940,18 +940,18 @@ int main(int argc, char **argv)
printf("Error: byte %d is wrong\n", k);
printf("outbuf value: %#x, inbuf value %#x, "
"right value: %#x\n",
- (int)ob[k], (int)(data[i].data[k]),
+ (int)ob[k], (int)(data[i].data[k]),
(int)(data[j].data[k]));
CHECK(ERROR);
}
}
printf("iconv from %s to %s was successfully done\n",
- data[i].name, data[j].name);
-
+ data[i].name, data[j].name);
+
}
}
-
+
d = 0;
for (i = 0; i < conversions; i++)
for (j = 0; j < conversions; j++)
@@ -960,14 +960,14 @@ int main(int argc, char **argv)
exit(0);
}
-#else /* #if defined(_ICONV_CONVERTER_UTF_8) || ... */
+#else /* #if defined(_ICONV_FROM_ENCODING_UTF_8) || ... */
int main(int argc, char **argv)
{
puts("None of UTF-8, EUC-JP, SHIFT-JIS and UCS-2_INTERNAL converters "
"linked, SKIP test");
exit(0);
}
-#endif /* #if defined(_ICONV_CONVERTER_UTF_8) || ... */
+#endif /* #if defined(_ICONV_FROM_ENCODING_UTF_8) || ... */
#else /* #ifdef _ICONV_ENABLED */
int main(int argc, char **argv)
@@ -976,4 +976,3 @@ int main(int argc, char **argv)
exit(0);
}
#endif /* #ifdef _ICONV_ENABLED */
-
diff --git a/newlib/testsuite/newlib.iconv/iconvnm.c b/newlib/testsuite/newlib.iconv/iconvnm.c
index d7ef2162c..b3ebc4765 100644
--- a/newlib/testsuite/newlib.iconv/iconvnm.c
+++ b/newlib/testsuite/newlib.iconv/iconvnm.c
@@ -33,13 +33,13 @@
#ifdef _ICONV_ENABLED
char *good_names[] = {
-#ifdef _ICONV_CONVERTER_ISO_8859_5
+#ifdef _ICONV_FROM_ENCODING_ISO_8859_5
"iso_8859_5", "iso-8859-5", "iso-8859_5", "IsO-8859_5"
-#elif defined _ICONV_CONVERTER_US_ASCII
+#elif defined _ICONV_FROM_ENCODING_US_ASCII
"us_ascii", "US_ASCII", "us-ASCII", "US-ASCII"
-#elif defined _ICONV_CONVERTER_EUC_JP
+#elif defined _ICONV_FROM_ENCODING_EUC_JP
"euc-jp", "EUC_JP", "euc-JP", "EUC-JP"
-#elif defined _ICONV_CONVERTER_UTF_8
+#elif defined _ICONV_FROM_ENCODING_UTF_8
"utf_8", "UTF_8", "uTf-8", "UTF-8"
#else
#endif
diff --git a/newlib/testsuite/newlib.iconv/iconvru.c b/newlib/testsuite/newlib.iconv/iconvru.c
index 7f02ebcbd..aa56603e6 100644
--- a/newlib/testsuite/newlib.iconv/iconvru.c
+++ b/newlib/testsuite/newlib.iconv/iconvru.c
@@ -32,11 +32,11 @@
#ifdef _ICONV_ENABLED
-#if defined(_ICONV_CONVERTER_UTF_8) || \
- defined(_ICONV_CONVERTER_ISO_8859_5) || \
- defined(_ICONV_CONVERTER_KOI8_R)
+#if defined(_ICONV_FROM_ENCODING_UTF_8) || \
+ defined(_ICONV_FROM_ENCODING_ISO_8859_5) || \
+ defined(_ICONV_FROM_ENCODING_KOI8_R)
-#ifdef _ICONV_CONVERTER_ISO_8859_5
+#ifdef _ICONV_FROM_ENCODING_ISO_8859_5
char iso_8859_5[] =
{
0xbe,0xdf,0xd5,0xe0,0xd0,0xe2,0xde,0xe0,0xeb,0x20,
@@ -137,9 +137,9 @@ char iso_8859_5[] =
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,
0x2d,0x2d,0x3e,0x0a
};
-#endif /* #ifdef _ICONV_CONVERTER_ISO_8859_5 */
+#endif /* #ifdef _ICONV_FROM_ENCODING_ISO_8859_5 */
-#ifdef _ICONV_CONVERTER_KOI8_R
+#ifdef _ICONV_FROM_ENCODING_KOI8_R
char koi8_r[] =
{
0xef,0xd0,0xc5,0xd2,0xc1,0xd4,0xcf,0xd2,0xd9,0x20,
@@ -240,9 +240,9 @@ char koi8_r[] =
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,
0x2d,0x2d,0x3e,0x0a
};
-#endif /* #ifdef _ICONV_CONVERTER_KOI8_R */
+#endif /* #ifdef _ICONV_FROM_ENCODING_KOI8_R */
-#ifdef _ICONV_CONVERTER_UTF_8
+#ifdef _ICONV_FROM_ENCODING_UTF_8
char utf8[] =
{
0xd0,0x9e,0xd0,0xbf,0xd0,0xb5,0xd1,0x80,0xd0,0xb0,
@@ -365,13 +365,13 @@ struct iconv_data
struct iconv_data data[] =
{
-#ifdef _ICONV_CONVERTER_ISO_8859_5
+#ifdef _ICONV_FROM_ENCODING_ISO_8859_5
{sizeof(iso_8859_5), "ISO-8859-5", (char *)iso_8859_5},
#endif
-#ifdef _ICONV_CONVERTER_KOI8_R
+#ifdef _ICONV_FROM_ENCODING_KOI8_R
{sizeof(koi8_r), "KOI8-R", (char *)koi8_r},
#endif
-#ifdef _ICONV_CONVERTER_UTF_8
+#ifdef _ICONV_FROM_ENCODING_UTF_8
{sizeof(utf8), "UTF-8", (char *)utf8},
#endif
{0, NULL, NULL}
@@ -471,13 +471,13 @@ int main(int argc, char **argv)
exit(0);
}
-#else /* #if defined(_ICONV_CONVERTER_UTF_8) || ... */
+#else /* #if defined(_ICONV_FROM_ENCODING_UTF_8) || ... */
int main(int argc, char **argv)
{
puts("None of ISO-8859-5, KOI8-R and UTF-8 converters linked, SKIP test");
exit(0);
}
-#endif /* #if defined(_ICONV_CONVERTER_UTF_8) || ... */
+#endif /* #if defined(_ICONV_FROM_ENCODING_UTF_8) || ... */
#else /* #ifdef _ICONV_ENABLED */
int main(int argc, char **argv)
--
2.27.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] libc/iconv: Detect CES handler loading failure
2020-07-09 23:58 [PATCH 1/4] libc/iconv: Detect CES handler loading failure Keith Packard
` (2 preceding siblings ...)
2020-07-09 23:58 ` [PATCH 4/4] testsuite: Fix iconv tests to use new encoding config defines Keith Packard
@ 2020-07-10 10:05 ` Corinna Vinschen
2020-07-11 0:26 ` Keith Packard
3 siblings, 1 reply; 6+ messages in thread
From: Corinna Vinschen @ 2020-07-10 10:05 UTC (permalink / raw)
To: Keith Packard; +Cc: newlib
On Jul 9 16:58, Keith Packard via Newlib wrote:
> Fix the code checking for character set loading failure so that
> it checks the return value from the init function.
>
> Signed-off-by: Keith Packard <keithp@keithp.com>
> ---
> newlib/libc/iconv/ces/euc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/newlib/libc/iconv/ces/euc.c b/newlib/libc/iconv/ces/euc.c
> index 29d36f941..ebd7091b0 100644
> --- a/newlib/libc/iconv/ces/euc.c
> +++ b/newlib/libc/iconv/ces/euc.c
> @@ -306,7 +306,7 @@ ok:
> data->data[i] = _iconv_to_ucs_ces_handlers_table.init (
> rptr,
> data->desc[i].csname);
> - if (data->data == NULL)
> + if (data->data[i] == NULL)
> goto error;
> }
>
> --
> 2.27.0
Pushed.
Just, please create patchsets with cover letter. It's better for
replies in terms of the entire patchset vs. replies to a single
patch.
Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] libc/iconv: Detect CES handler loading failure
2020-07-10 10:05 ` [PATCH 1/4] libc/iconv: Detect CES handler loading failure Corinna Vinschen
@ 2020-07-11 0:26 ` Keith Packard
0 siblings, 0 replies; 6+ messages in thread
From: Keith Packard @ 2020-07-11 0:26 UTC (permalink / raw)
To: Corinna Vinschen; +Cc: newlib
[-- Attachment #1: Type: text/plain, Size: 288 bytes --]
Corinna Vinschen <vinschen@redhat.com> writes:
> Just, please create patchsets with cover letter. It's better for
> replies in terms of the entire patchset vs. replies to a single
> patch.
Will do. Thanks for the reminder! And thanks for accepting these patches.
--
-keith
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-07-11 0:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-09 23:58 [PATCH 1/4] libc/iconv: Detect CES handler loading failure Keith Packard
2020-07-09 23:58 ` [PATCH 2/4] libc/iconv: Remove unneeded pointer var for _iconv_aliases Keith Packard
2020-07-09 23:58 ` [PATCH 3/4] libc/iconv: find_alias was mis-computing remaining alias table length Keith Packard
2020-07-09 23:58 ` [PATCH 4/4] testsuite: Fix iconv tests to use new encoding config defines Keith Packard
2020-07-10 10:05 ` [PATCH 1/4] libc/iconv: Detect CES handler loading failure Corinna Vinschen
2020-07-11 0:26 ` Keith Packard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).