Skip to content

Commit bb4f73b

Browse files
committed
Avoid signed integer overflow during shifts.
1 parent cc27bbd commit bb4f73b

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2019-03-07 Bruno Haible <bruno@clisp.org>
2+
3+
Avoid signed integer overflow during shifts.
4+
Reported by Jeffrey Walton <noloader@gmail.com>.
5+
* lib/tcvn.h (tcvn_wctomb): Use unsigned integer type for bit mask
6+
operation.
7+
* lib/viscii.h (viscii_wctomb): Likewise.
8+
19
2019-03-04 Bruno Haible <bruno@clisp.org>
210

311
Add support for --enable-relocatable to libcharset.

lib/tcvn.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 1999-2002, 2004, 2016 Free Software Foundation, Inc.
2+
* Copyright (C) 1999-2002, 2004, 2016, 2019 Free Software Foundation, Inc.
33
* This file is part of the GNU LIBICONV Library.
44
*
55
* The GNU LIBICONV Library is free software; you can redistribute it
@@ -217,7 +217,7 @@ static int
217217
tcvn_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, size_t n)
218218
{
219219
unsigned char c = 0;
220-
if (wc < 0x0080 && (wc >= 0x0020 || (0x00fe0076 & (1 << wc)) == 0)) {
220+
if (wc < 0x0080 && (wc >= 0x0020 || (0x00fe0076U & (1U << wc)) == 0)) {
221221
*r = wc;
222222
return 1;
223223
}

lib/viscii.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 1999-2001, 2016 Free Software Foundation, Inc.
2+
* Copyright (C) 1999-2001, 2016, 2019 Free Software Foundation, Inc.
33
* This file is part of the GNU LIBICONV Library.
44
*
55
* The GNU LIBICONV Library is free software; you can redistribute it
@@ -124,7 +124,7 @@ static int
124124
viscii_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, size_t n)
125125
{
126126
unsigned char c = 0;
127-
if (wc < 0x0080 && (wc >= 0x0020 || (0x42100064 & (1 << wc)) == 0)) {
127+
if (wc < 0x0080 && (wc >= 0x0020 || (0x42100064U & (1U << wc)) == 0)) {
128128
*r = wc;
129129
return 1;
130130
}

0 commit comments

Comments
 (0)