Mercurial > pidgin.yaz
comparison libpurple/protocols/myspace/message.c @ 17976:b2d81d13f015
Be more careful about null strings in %s format specifier in debug messages.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Sun, 05 Aug 2007 03:02:17 +0000 |
parents | acff371d7908 |
children | e0cac5db762b |
comparison
equal
deleted
inserted
replaced
17975:496affa42816 | 17976:b2d81d13f015 |
---|---|
694 * msim_msg_get_string() if you want a string, which in some cases is same as this. | 694 * msim_msg_get_string() if you want a string, which in some cases is same as this. |
695 */ | 695 */ |
696 static gchar * | 696 static gchar * |
697 msim_msg_pack_element_data(MsimMessageElement *elem) | 697 msim_msg_pack_element_data(MsimMessageElement *elem) |
698 { | 698 { |
699 g_return_val_if_fail(elem != NULL, NULL); | |
700 | |
699 switch (elem->type) | 701 switch (elem->type) |
700 { | 702 { |
701 case MSIM_TYPE_INTEGER: | 703 case MSIM_TYPE_INTEGER: |
702 return g_strdup_printf("%d", GPOINTER_TO_UINT(elem->data)); | 704 return g_strdup_printf("%d", GPOINTER_TO_UINT(elem->data)); |
703 | 705 |
744 | 746 |
745 return gs->str; | 747 return gs->str; |
746 } | 748 } |
747 | 749 |
748 default: | 750 default: |
749 purple_debug_info("msim", "field %s, unknown type %d\n", elem->name, elem->type); | 751 purple_debug_info("msim", "field %s, unknown type %d\n", |
752 elem->name ? elem->name : "(NULL)", | |
753 elem->type); | |
750 return NULL; | 754 return NULL; |
751 } | 755 } |
752 } | 756 } |
753 | 757 |
754 /** Pack an element into its protcol representation inside a dictionary. | 758 /** Pack an element into its protcol representation inside a dictionary. |
1003 g_strfreev(elements); | 1007 g_strfreev(elements); |
1004 break; | 1008 break; |
1005 } | 1009 } |
1006 | 1010 |
1007 #ifdef MSIM_DEBUG_PARSE | 1011 #ifdef MSIM_DEBUG_PARSE |
1008 purple_debug_info("msim", "-- %s: %s\n", key, value); | 1012 purple_debug_info("msim", "-- %s: %s\n", key ? key : "(NULL)", |
1013 value ? value : "(NULL)"); | |
1009 #endif | 1014 #endif |
1010 | 1015 |
1011 /* XXX: This overwrites duplicates. */ | 1016 /* XXX: This overwrites duplicates. */ |
1012 /* TODO: make the GHashTable values be GList's, and append to the list if | 1017 /* TODO: make the GHashTable values be GList's, and append to the list if |
1013 * there is already a value of the same key name. This is important for | 1018 * there is already a value of the same key name. This is important for |
1093 msim_msg_get_string(MsimMessage *msg, const gchar *name) | 1098 msim_msg_get_string(MsimMessage *msg, const gchar *name) |
1094 { | 1099 { |
1095 MsimMessageElement *elem; | 1100 MsimMessageElement *elem; |
1096 | 1101 |
1097 elem = msim_msg_get(msg, name); | 1102 elem = msim_msg_get(msg, name); |
1098 if (!elem) | 1103 g_return_val_if_fail(elem != NULL , NULL); |
1099 return NULL; | |
1100 | 1104 |
1101 switch (elem->type) | 1105 switch (elem->type) |
1102 { | 1106 { |
1103 case MSIM_TYPE_INTEGER: | 1107 case MSIM_TYPE_INTEGER: |
1104 return g_strdup_printf("%d", GPOINTER_TO_UINT(elem->data)); | 1108 return g_strdup_printf("%d", GPOINTER_TO_UINT(elem->data)); |
1112 /* Already unescaped. */ | 1116 /* Already unescaped. */ |
1113 return g_strdup((gchar *)elem->data); | 1117 return g_strdup((gchar *)elem->data); |
1114 | 1118 |
1115 default: | 1119 default: |
1116 purple_debug_info("msim", "msim_msg_get_string: type %d unknown, name %s\n", | 1120 purple_debug_info("msim", "msim_msg_get_string: type %d unknown, name %s\n", |
1117 elem->type, name); | 1121 elem->type, name ? name : "(NULL)"); |
1118 return NULL; | 1122 return NULL; |
1119 } | 1123 } |
1120 } | 1124 } |
1121 | 1125 |
1122 /** Return an element as a new list. Caller frees with msim_msg_list_free(). */ | 1126 /** Return an element as a new list. Caller frees with msim_msg_list_free(). */ |
1137 case MSIM_TYPE_RAW: | 1141 case MSIM_TYPE_RAW: |
1138 return msim_msg_list_parse((gchar *)elem->data); | 1142 return msim_msg_list_parse((gchar *)elem->data); |
1139 | 1143 |
1140 default: | 1144 default: |
1141 purple_debug_info("msim_msg_get_list", "type %d unknown, name %s\n", | 1145 purple_debug_info("msim_msg_get_list", "type %d unknown, name %s\n", |
1142 elem->type, name); | 1146 elem->type, name ? name : "(NULL)"); |
1143 return NULL; | 1147 return NULL; |
1144 } | 1148 } |
1145 } | 1149 } |
1146 | 1150 |
1147 /** Parse a \034-deliminated and =-separated string into a dictionary. TODO */ | 1151 /** Parse a \034-deliminated and =-separated string into a dictionary. TODO */ |
1170 case MSIM_TYPE_RAW: | 1174 case MSIM_TYPE_RAW: |
1171 return msim_msg_dictionary_parse((gchar *)elem->data); | 1175 return msim_msg_dictionary_parse((gchar *)elem->data); |
1172 | 1176 |
1173 default: | 1177 default: |
1174 purple_debug_info("msim_msg_get_dictionary", "type %d unknown, name %s\n", | 1178 purple_debug_info("msim_msg_get_dictionary", "type %d unknown, name %s\n", |
1175 elem->type, name); | 1179 elem->type, name ? name : "(NULL)"); |
1176 return NULL; | 1180 return NULL; |
1177 } | 1181 } |
1178 } | 1182 } |
1179 | 1183 |
1180 /** Return the data of an element of a given name, as an integer. | 1184 /** Return the data of an element of a given name, as an integer. |
1225 gchar **binary_data, gsize *binary_length) | 1229 gchar **binary_data, gsize *binary_length) |
1226 { | 1230 { |
1227 MsimMessageElement *elem; | 1231 MsimMessageElement *elem; |
1228 | 1232 |
1229 elem = msim_msg_get(msg, name); | 1233 elem = msim_msg_get(msg, name); |
1234 if (!elem) | |
1235 return FALSE; | |
1230 | 1236 |
1231 switch (elem->type) | 1237 switch (elem->type) |
1232 { | 1238 { |
1233 case MSIM_TYPE_RAW: | 1239 case MSIM_TYPE_RAW: |
1234 /* Incoming messages are tagged with MSIM_TYPE_RAW, and | 1240 /* Incoming messages are tagged with MSIM_TYPE_RAW, and |
1275 * | 1281 * |
1276 * return (GString *)elem->data; */ | 1282 * return (GString *)elem->data; */ |
1277 | 1283 |
1278 default: | 1284 default: |
1279 purple_debug_info("msim", "msim_msg_get_binary: unhandled type %d for key %s\n", | 1285 purple_debug_info("msim", "msim_msg_get_binary: unhandled type %d for key %s\n", |
1280 elem->type, name); | 1286 elem->type, name ? name : "(NULL)"); |
1281 return FALSE; | 1287 return FALSE; |
1282 } | 1288 } |
1283 } | 1289 } |