changeset: 6533:ff560d1f3f7a
user: Kevin McCarthy <[email protected]>
date: Thu Nov 26 11:01:19 2015 -0800
link: http://dev.mutt.org/hg/mutt/rev/ff560d1f3f7a
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).
diffs (38 lines):
diff -r 94186a96ca17 -r ff560d1f3f7a smtp.c
--- a/smtp.c Tue Nov 24 21:45:58 2015 -0800
+++ b/smtp.c Thu Nov 26 11:01:19 2015 -0800
@@ -242,12 +242,18 @@
/* 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 @@
/* 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))