{"thread":{"id":"7065","subject":"[PATCH 5/6] Fix some \"comparison is always true/false\" warnings.","startedAt":"2007-03-03T18:28:57Z","lastAt":"2007-03-08T06:45:34Z","messageCount":4,"participants":["Ramsay Jones","Karl Hasselström"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"36188","messageId":"45E9BE69.4070508@ramsay1.demon.co.uk","threadId":"7065","inReplyTo":null,"subject":"[PATCH 5/6] Fix some \"comparison is always true/false\" warnings.","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2007-03-03T18:28:57Z","receivedAt":"2007-03-03T18:28:57Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nOn Cygwin the wchar_t type is an unsigned short (16-bit) int.\nThis results in the above warnings from the return statement in\nthe wcwidth() function (in particular, the expressions involving\nconstants with values larger than 0xffff). Simply replace the\nuse of wchar_t with an unsigned int, typedef-ed as ucs_char_t.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n---\n  utf8.c |   10 ++++++----\n  1 files changed, 6 insertions(+), 4 deletions(-)\n\ndiff --git a/utf8.c b/utf8.c\nindex 7c80eec..211e100 100644\n--- a/utf8.c\n+++ b/utf8.c\n@@ -3,13 +3,15 @@\n\n  /* This code is originally from http://www.cl.cam.ac.uk/~mgk25/ucs/ */\n\n+typedef unsigned int ucs_char_t;  /* assuming 32bit int */\n+\n  struct interval {\n    int first;\n    int last;\n  };\n\n  /* auxiliary function for binary search in interval table */\n-static int bisearch(wchar_t ucs, const struct interval *table, int max) {\n+static int bisearch(ucs_char_t ucs, const struct interval *table, int max) {\n  \tint min = 0;\n  \tint mid;\n\n@@ -56,11 +58,11 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max) {\n   *      ISO 8859-1 and WGL4 characters, Unicode control characters,\n   *      etc.) have a column width of 1.\n   *\n- * This implementation assumes that wchar_t characters are encoded\n+ * This implementation assumes that ucs_char_t characters are encoded\n   * in ISO 10646.\n   */\n\n-static int wcwidth(wchar_t ch)\n+static int wcwidth(ucs_char_t ch)\n  {\n  \t/*\n  \t * Sorted list of non-overlapping intervals of non-spacing characters,\n@@ -157,7 +159,7 @@ static int wcwidth(wchar_t ch)\n  int utf8_width(const char **start)\n  {\n  \tunsigned char *s = (unsigned char *)*start;\n-\twchar_t ch;\n+\tucs_char_t ch;\n\n  \tif (*s < 0x80) {\n  \t\t/* 0xxxxxxx */\n-- \n1.5.0\n"},{"id":"36286","messageId":"20070305074502.GA31507@diana.vm.bytemark.co.uk","threadId":"7065","inReplyTo":"45E9BE69.4070508@ramsay1.demon.co.uk","subject":"Re: [PATCH 5/6] Fix some \"comparison is always true/false\" warnings.","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2007-03-05T07:45:02Z","receivedAt":"2007-03-05T07:45:02Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2007-03-03 18:28:57 +0000, Ramsay Jones wrote:\n\n> +typedef unsigned int ucs_char_t;  /* assuming 32bit int */\n\nUmm ... wouldn't an uint32_t be a better fit here?\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"36567","messageId":"45EF0D0D.4060904@ramsay1.demon.co.uk","threadId":"7065","inReplyTo":"20070305074502.GA31507@diana.vm.bytemark.co.uk","subject":"Re: [PATCH 5/6] Fix some \"comparison is always true/false\" warnings.","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2007-03-07T19:05:49Z","receivedAt":"2007-03-07T19:05:49Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"Karl Hasselström wrote:\n> On 2007-03-03 18:28:57 +0000, Ramsay Jones wrote:\n> \n>> +typedef unsigned int ucs_char_t;  /* assuming 32bit int */\n> \n> Umm ... wouldn't an uint32_t be a better fit here?\n> \n\nYes, but I did not want to add a dependency on a C99 header\n(i.e. <stdint.h>). I had a vague recollection that Linus had\nstated that git was probably broken if int wasn't 32 bits, so ...\n\nThis was before I realized that a recent change to git meant\nthat git was already including C99 headers <inttypes.h> and,\ntherefore indirectly, <stdint.h>.\n\nSo, if it is OK to depend on those headers, then an uin32_t may\nindeed be a better fit.\n\nAll the best,\n\nRamsay Jones\n"},{"id":"36593","messageId":"20070308064534.GA5981@diana.vm.bytemark.co.uk","threadId":"7065","inReplyTo":"45EF0D0D.4060904@ramsay1.demon.co.uk","subject":"Re: [PATCH 5/6] Fix some \"comparison is always true/false\" warnings.","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2007-03-08T06:45:34Z","receivedAt":"2007-03-08T06:45:34Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2007-03-07 19:05:49 +0000, Ramsay Jones wrote:\n\n> Karl Hasselström wrote:\n>\n> > Umm ... wouldn't an uint32_t be a better fit here?\n>\n> Yes, but I did not want to add a dependency on a C99 header (i.e.\n> <stdint.h>). I had a vague recollection that Linus had stated that\n> git was probably broken if int wasn't 32 bits, so ...\n>\n> This was before I realized that a recent change to git meant that\n> git was already including C99 headers <inttypes.h> and, therefore\n> indirectly, <stdint.h>.\n\nYour approach is much more sophisticated than mine. :-) I just\nthought, \"wow, this _screams_ for a uint32_t -- hmm, is it OK to use\nthat?\", and then did \"git grep uint32_t\" and got about a screenful of\nhits.\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"}]}