Mercurial > hg
comparison mcabber/src/roster.c @ 670:2cd0805515a4
Fix a bug in roster_find()
When doing a name-based search, roster_find() did not check type
correctly, which could lead to a segfault in some other places.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 15 Jan 2006 10:00:03 +0100 |
parents | 2b87065270f3 |
children | e175f5d96f04 |
comparison
equal
deleted
inserted
replaced
669:2b87065270f3 | 670:2cd0805515a4 |
---|---|
205 if (! (a->type & b->type)) | 205 if (! (a->type & b->type)) |
206 return -1; // arbitrary (but should be != 0, of course) | 206 return -1; // arbitrary (but should be != 0, of course) |
207 return strcasecmp(a->jid, b->jid); | 207 return strcasecmp(a->jid, b->jid); |
208 } | 208 } |
209 | 209 |
210 // Comparison function used to search in the roster (compares names and types) | |
211 static gint roster_compare_name_type(roster *a, roster *b) { | |
212 if (! (a->type & b->type)) | |
213 return -1; // arbitrary (but should be != 0, of course) | |
214 return strcasecmp(a->name, b->name); | |
215 } | |
216 | |
210 // Comparison function used to sort the roster (by name) | 217 // Comparison function used to sort the roster (by name) |
211 static gint roster_compare_name(roster *a, roster *b) { | 218 static gint roster_compare_name(roster *a, roster *b) { |
212 return strcasecmp(a->name, b->name); | 219 return strcasecmp(a->name, b->name); |
213 } | 220 } |
214 | 221 |
232 if (type == jidsearch) { | 239 if (type == jidsearch) { |
233 sample.jid = (gchar*)jidname; | 240 sample.jid = (gchar*)jidname; |
234 comp = (GCompareFunc)&roster_compare_jid_type; | 241 comp = (GCompareFunc)&roster_compare_jid_type; |
235 } else if (type == namesearch) { | 242 } else if (type == namesearch) { |
236 sample.name = (gchar*)jidname; | 243 sample.name = (gchar*)jidname; |
237 comp = (GCompareFunc)&roster_compare_name; | 244 comp = (GCompareFunc)&roster_compare_name_type; |
238 } else | 245 } else |
239 return NULL; // should not happen | 246 return NULL; // should not happen |
240 | 247 |
241 while (sl_roster_elt) { | 248 while (sl_roster_elt) { |
242 roster *roster_elt = (roster*)sl_roster_elt->data; | 249 roster *roster_elt = (roster*)sl_roster_elt->data; |