Skip to content

Commit

Permalink
Fix some "comparison is always true/false" warnings.
Browse files Browse the repository at this point in the history
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 <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Ramsay Jones authored and Junio C Hamano committed Mar 4, 2007
1 parent 41b2001 commit 2832114
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

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

typedef unsigned int ucs_char_t; /* assuming 32bit int */

struct interval {
int first;
int last;
};

/* auxiliary function for binary search in interval table */
static int bisearch(wchar_t ucs, const struct interval *table, int max) {
static int bisearch(ucs_char_t ucs, const struct interval *table, int max) {
int min = 0;
int mid;

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

static int wcwidth(wchar_t ch)
static int wcwidth(ucs_char_t ch)
{
/*
* Sorted list of non-overlapping intervals of non-spacing characters,
Expand Down Expand Up @@ -157,7 +159,7 @@ static int wcwidth(wchar_t ch)
int utf8_width(const char **start)
{
unsigned char *s = (unsigned char *)*start;
wchar_t ch;
ucs_char_t ch;

if (*s < 0x80) {
/* 0xxxxxxx */
Expand Down

0 comments on commit 2832114

Please sign in to comment.