From: Kevin McCarthy Date: Thu, 26 Nov 2015 19:01:19 +0000 (-0800) Subject: Clean up address_uses_unicode() (closes #3794) X-Git-Tag: neomutt-20160404~93 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=936acc4fa79b8a66ca5fd22f0a00b43a2abe0a58;p=neomutt Clean up address_uses_unicode() (closes #3794) Pull the null check out of the loop. Use a bit comparison to detect if the high bit is set: this avoids a warning for platforms where char is implicitly signed (where comparing < 128 is always true). --- diff --git a/smtp.c b/smtp.c index f18b93db4..da80f5e7e 100644 --- a/smtp.c +++ b/smtp.c @@ -242,12 +242,18 @@ smtp_data (CONNECTION * conn, const char *msgfile) /* Returns 1 if a contains at least one 8-bit character, 0 if none do. */ -static int -address_uses_unicode(const char * a) { - while(a && *a > 0 && *a < 128) +static int address_uses_unicode(const char *a) +{ + if (!a) + return 0; + + while (*a) + { + if ((unsigned char) *a & (1<<7)) + return 1; a++; - if(a && *a) - return 1; + } + return 0; } @@ -255,8 +261,8 @@ address_uses_unicode(const char * a) { /* Returns 1 if any address in a contains at least one 8-bit * character, 0 if none do. */ -static int -addresses_use_unicode(const ADDRESS* a) { +static int addresses_use_unicode(const ADDRESS* a) +{ while (a) { if(a->mailbox && !a->group && address_uses_unicode(a->mailbox))