* [PATCH 5/6] Fix some "comparison is always true/false" warnings.
@ 2007-03-03 18:28 Ramsay Jones
2007-03-05 7:45 ` Karl Hasselström
0 siblings, 1 reply; 4+ messages in thread
From: Ramsay Jones @ 2007-03-03 18:28 UTC (permalink / raw)
To: Junio C Hamano; +Cc: GIT Mailing-list
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 5/6] Fix some "comparison is always true/false" warnings.
2007-03-03 18:28 [PATCH 5/6] Fix some "comparison is always true/false" warnings Ramsay Jones
@ 2007-03-05 7:45 ` Karl Hasselström
2007-03-07 19:05 ` Ramsay Jones
0 siblings, 1 reply; 4+ messages in thread
From: Karl Hasselström @ 2007-03-05 7:45 UTC (permalink / raw)
To: Ramsay Jones; +Cc: Junio C Hamano, GIT Mailing-list
On 2007-03-03 18:28:57 +0000, Ramsay Jones wrote:
> +typedef unsigned int ucs_char_t; /* assuming 32bit int */
Umm ... wouldn't an uint32_t be a better fit here?
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 5/6] Fix some "comparison is always true/false" warnings.
2007-03-05 7:45 ` Karl Hasselström
@ 2007-03-07 19:05 ` Ramsay Jones
2007-03-08 6:45 ` Karl Hasselström
0 siblings, 1 reply; 4+ messages in thread
From: Ramsay Jones @ 2007-03-07 19:05 UTC (permalink / raw)
To: Karl Hasselström; +Cc: Junio C Hamano, GIT Mailing-list
Karl Hasselström wrote:
> On 2007-03-03 18:28:57 +0000, Ramsay Jones wrote:
>
>> +typedef unsigned int ucs_char_t; /* assuming 32bit int */
>
> Umm ... wouldn't an uint32_t be a better fit here?
>
Yes, but I did not want to add a dependency on a C99 header
(i.e. <stdint.h>). I had a vague recollection that Linus had
stated that git was probably broken if int wasn't 32 bits, so ...
This was before I realized that a recent change to git meant
that git was already including C99 headers <inttypes.h> and,
therefore indirectly, <stdint.h>.
So, if it is OK to depend on those headers, then an uin32_t may
indeed be a better fit.
All the best,
Ramsay Jones
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 5/6] Fix some "comparison is always true/false" warnings.
2007-03-07 19:05 ` Ramsay Jones
@ 2007-03-08 6:45 ` Karl Hasselström
0 siblings, 0 replies; 4+ messages in thread
From: Karl Hasselström @ 2007-03-08 6:45 UTC (permalink / raw)
To: Ramsay Jones; +Cc: Junio C Hamano, GIT Mailing-list
On 2007-03-07 19:05:49 +0000, Ramsay Jones wrote:
> Karl Hasselström wrote:
>
> > Umm ... wouldn't an uint32_t be a better fit here?
>
> Yes, but I did not want to add a dependency on a C99 header (i.e.
> <stdint.h>). I had a vague recollection that Linus had stated that
> git was probably broken if int wasn't 32 bits, so ...
>
> This was before I realized that a recent change to git meant that
> git was already including C99 headers <inttypes.h> and, therefore
> indirectly, <stdint.h>.
Your approach is much more sophisticated than mine. :-) I just
thought, "wow, this _screams_ for a uint32_t -- hmm, is it OK to use
that?", and then did "git grep uint32_t" and got about a screenful of
hits.
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-03-08 6:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-03 18:28 [PATCH 5/6] Fix some "comparison is always true/false" warnings Ramsay Jones
2007-03-05 7:45 ` Karl Hasselström
2007-03-07 19:05 ` Ramsay Jones
2007-03-08 6:45 ` Karl Hasselström
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).