Skip to content

Commit 2832114

Browse files
Ramsay JonesJunio C Hamano
authored andcommitted
Fix some "comparison is always true/false" warnings.
On Cygwin the wchar_t type is an unsigned short (16-bit) int. This results in the above warnings from the return statement in the wcwidth() function (in particular, the expressions involving constants with values larger than 0xffff). Simply replace the use of wchar_t with an unsigned int, typedef-ed as ucs_char_t. Signed-off-by: Ramsay Jones <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 41b2001 commit 2832114

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

utf8.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
/* This code is originally from http://www.cl.cam.ac.uk/~mgk25/ucs/ */
55

6+
typedef unsigned int ucs_char_t; /* assuming 32bit int */
7+
68
struct interval {
79
int first;
810
int last;
911
};
1012

1113
/* auxiliary function for binary search in interval table */
12-
static int bisearch(wchar_t ucs, const struct interval *table, int max) {
14+
static int bisearch(ucs_char_t ucs, const struct interval *table, int max) {
1315
int min = 0;
1416
int mid;
1517

@@ -56,11 +58,11 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max) {
5658
* ISO 8859-1 and WGL4 characters, Unicode control characters,
5759
* etc.) have a column width of 1.
5860
*
59-
* This implementation assumes that wchar_t characters are encoded
61+
* This implementation assumes that ucs_char_t characters are encoded
6062
* in ISO 10646.
6163
*/
6264

63-
static int wcwidth(wchar_t ch)
65+
static int wcwidth(ucs_char_t ch)
6466
{
6567
/*
6668
* Sorted list of non-overlapping intervals of non-spacing characters,
@@ -157,7 +159,7 @@ static int wcwidth(wchar_t ch)
157159
int utf8_width(const char **start)
158160
{
159161
unsigned char *s = (unsigned char *)*start;
160-
wchar_t ch;
162+
ucs_char_t ch;
161163

162164
if (*s < 0x80) {
163165
/* 0xxxxxxx */

0 commit comments

Comments
 (0)