comparison libpurple/protocols/jabber/usermood.c @ 22795:5954c65ae4f4

Don't count the size of an array at runtime if it's known at compile time.
author Ethan Blanton <elb@pidgin.im>
date Wed, 30 Apr 2008 17:00:27 +0000
parents 665e04562de0
children 26eabe8e739b 5f9a24d1c25e 432d9176d054
comparison
equal deleted inserted replaced
22794:cc8903c59d6b 22795:5954c65ae4f4
145 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb); 145 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb);
146 } 146 }
147 147
148 static void do_mood_set_from_fields(PurpleConnection *gc, PurpleRequestFields *fields) { 148 static void do_mood_set_from_fields(PurpleConnection *gc, PurpleRequestFields *fields) {
149 JabberStream *js; 149 JabberStream *js;
150 int max_mood_idx; 150 const int max_mood_idx = sizeof(moodstrings) / sizeof(moodstrings[0]) - 1;
151 int selected_mood = purple_request_fields_get_choice(fields, "mood"); 151 int selected_mood = purple_request_fields_get_choice(fields, "mood");
152 152
153 if (!PURPLE_CONNECTION_IS_VALID(gc)) { 153 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
154 purple_debug_error("jabber", "Unable to set mood; account offline.\n"); 154 purple_debug_error("jabber", "Unable to set mood; account offline.\n");
155 return; 155 return;
156 } 156 }
157 157
158 js = gc->proto_data; 158 js = gc->proto_data;
159
160 /* This is ugly, but protects us from unexpected values. */
161 for (max_mood_idx = 0; moodstrings[max_mood_idx]; max_mood_idx++);
162 159
163 if (selected_mood < 0 || selected_mood >= max_mood_idx) { 160 if (selected_mood < 0 || selected_mood >= max_mood_idx) {
164 purple_debug_error("jabber", "Invalid mood index (%d) selected.\n", selected_mood); 161 purple_debug_error("jabber", "Invalid mood index (%d) selected.\n", selected_mood);
165 return; 162 return;
166 } 163 }