# HG changeset patch # User Timo Sirainen # Date 1500472158 -10800 # Node ID 125e78e85bcc71e0d273db232be561d57c6fd24f # Parent 239bc902f6dae64343d69a366a44d0ca45e6c633 lib-mail: Make sure mail_user_hash() won't return 0 as the hash. It doesn't seem to actually happen, but this makes sure of it. diff -r 239bc902f6da -r 125e78e85bcc src/lib-mail/mail-user-hash.c --- a/src/lib-mail/mail-user-hash.c Thu Jul 06 15:45:24 2017 +0300 +++ b/src/lib-mail/mail-user-hash.c Wed Jul 19 16:49:18 2017 +0300 @@ -42,6 +42,12 @@ } T_END; for (i = 0; i < sizeof(hash); i++) hash = (hash << CHAR_BIT) | md5[i]; + if (hash == 0) { + /* Make sure we don't return the hash as 0, since it's often + treated in a special way that won't work well. For example + trying to insert it into a hash table will assert-crash. */ + hash = 1; + } return hash; } diff -r 239bc902f6da -r 125e78e85bcc src/lib-mail/mail-user-hash.h --- a/src/lib-mail/mail-user-hash.h Thu Jul 06 15:45:24 2017 +0300 +++ b/src/lib-mail/mail-user-hash.h Wed Jul 19 16:49:18 2017 +0300 @@ -2,7 +2,7 @@ #define MAIL_USER_HASH /* Return a hash for username, based on given format. The format can use - %n, %d and %u variables. */ + %n, %d and %u variables. The returned hash is never 0. */ unsigned int mail_user_hash(const char *username, const char *format); #endif