git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/6] Fix some "comparison is always true/false" warnings.

From
Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Date
Mar 3, 2007, 18:28 UTC
Message-ID
<45E9BE69.4070508@ramsay1.demon.co.uk>

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>
---
  utf8.c |   10 ++++++----
  1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/utf8.c b/utf8.c
index 7c80eec..211e100 100644
--- a/utf8.c
+++ b/utf8.c
@@ -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;

@@ -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,
@@ -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 */
-- 
1.5.0
Next: Karl Hasselström
Message 1 of 4 in “Fix some "comparison is always true/false" warnings.”
  1. 5/6 Fix some "comparison is always true/false" warnings.Ramsay Jones, Mar 3, 2007
  2. Karl HasselströmMar 5, 2007
  3. Ramsay JonesMar 7, 2007
  4. Karl HasselströmMar 8, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.