Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/compl.c @ 2035:dac609275117
Fix endless loop on exhaustion of completion category pool
author | Myhailo Danylenko <isbear@ukrpost.net> |
---|---|
date | Sun, 14 Oct 2012 18:06:50 +0200 |
parents | c1f9a4d47e05 |
children | 0cb8ea02e472 |
comparison
equal
deleted
inserted
replaced
2034:c7d40b9b2bb9 | 2035:dac609275117 |
---|---|
95 // Returns 0, if no more categories can be allocated. | 95 // Returns 0, if no more categories can be allocated. |
96 // Note, that user should not make any assumptions about id nature, | 96 // Note, that user should not make any assumptions about id nature, |
97 // as it is likely to change in future. | 97 // as it is likely to change in future. |
98 guint compl_new_category(void) | 98 guint compl_new_category(void) |
99 { | 99 { |
100 const guint maxcat = 8 * sizeof (registered_cats); | |
100 guint i = 0; | 101 guint i = 0; |
101 while ((registered_cats >> i) & 1) | 102 while ((registered_cats >> i) & 1 && i < maxcat) |
102 i++; | 103 i++; |
103 if (i >= 8 * sizeof (registered_cats)) | 104 if (i >= maxcat) |
104 return 0; | 105 return 0; |
105 else { | 106 else { |
106 guint64 id = 1 << i; | 107 guint64 id = 1 << i; |
107 registered_cats |= id; | 108 registered_cats |= id; |
108 return i+1; | 109 return i+1; |