Avoid signed integer overflow during shifts.
diff --git a/ChangeLog b/ChangeLog
index 309ba8f..094b793 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-03-07 Bruno Haible <bruno@clisp.org>
+
+ Avoid signed integer overflow during shifts.
+ Reported by Jeffrey Walton <noloader@gmail.com>.
+ * lib/tcvn.h (tcvn_wctomb): Use unsigned integer type for bit mask
+ operation.
+ * lib/viscii.h (viscii_wctomb): Likewise.
+
2019-03-04 Bruno Haible <bruno@clisp.org>
Add support for --enable-relocatable to libcharset.
diff --git a/lib/tcvn.h b/lib/tcvn.h
index 44d96ef..87a64d7 100644
--- a/lib/tcvn.h
+++ b/lib/tcvn.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1999-2002, 2004, 2016 Free Software Foundation, Inc.
+ * Copyright (C) 1999-2002, 2004, 2016, 2019 Free Software Foundation, Inc.
* This file is part of the GNU LIBICONV Library.
*
* The GNU LIBICONV Library is free software; you can redistribute it
@@ -217,7 +217,7 @@
tcvn_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, size_t n)
{
unsigned char c = 0;
- if (wc < 0x0080 && (wc >= 0x0020 || (0x00fe0076 & (1 << wc)) == 0)) {
+ if (wc < 0x0080 && (wc >= 0x0020 || (0x00fe0076U & (1U << wc)) == 0)) {
*r = wc;
return 1;
}
diff --git a/lib/viscii.h b/lib/viscii.h
index e5c6209..a298e99 100644
--- a/lib/viscii.h
+++ b/lib/viscii.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1999-2001, 2016 Free Software Foundation, Inc.
+ * Copyright (C) 1999-2001, 2016, 2019 Free Software Foundation, Inc.
* This file is part of the GNU LIBICONV Library.
*
* The GNU LIBICONV Library is free software; you can redistribute it
@@ -124,7 +124,7 @@
viscii_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, size_t n)
{
unsigned char c = 0;
- if (wc < 0x0080 && (wc >= 0x0020 || (0x42100064 & (1 << wc)) == 0)) {
+ if (wc < 0x0080 && (wc >= 0x0020 || (0x42100064U & (1U << wc)) == 0)) {
*r = wc;
return 1;
}