soc.2012.statscollector: 5940f48f: Remove warnings as they break windows co...

sanket at soc.pidgin.im sanket at soc.pidgin.im
Thu May 17 01:36:02 EDT 2012


----------------------------------------------------------------------
Revision: 5940f48f916c84b754f9585b950d701fa47a0ca6
Parent:   24aa37e2fa24137b3f94b3e1fca5cbf35519ac2a
Author:   sanket at soc.pidgin.im
Date:     05/17/12 02:30:38
Branch:   im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/5940f48f916c84b754f9585b950d701fa47a0ca6

Changelog: 

Remove warnings as they break windows compile

const char * coversion could be tricky with windows hence remove all warnings
(also) a future lesson :-).

There was a small bug with switch:case where I forgot to break in between,
it's been fixed inline this commit

Changes against parent 24aa37e2fa24137b3f94b3e1fca5cbf35519ac2a

  patched  pidgin/plugins/statscollector.c

-------------- next part --------------
============================================================
--- pidgin/plugins/statscollector.c	e6b510c9bf1f1178aa863e675140bfd4243a5e18
+++ pidgin/plugins/statscollector.c	f6b41bdcb463aa9a67fd7a13551e7ea4b858665f
@@ -33,7 +33,7 @@ save_xml(){
    * final modified XML out of it to be flushed
    */
 
-  GHashTableIter * iter;
+  GHashTableIter iter;
   gpointer key, value;
   xmlnode *nroot, *nacc, *nplugins, *node;
   char *data;
@@ -90,17 +90,22 @@ get_cpuinfo_xml(){
 
   /* Obtains a XML node containing the CPU info */
 
-  xmlnode *root, *languages, *node, *ver, *os, *cpu, *native_arch, *app_arch;
+  xmlnode *root, *languages, *node, *ver, *os, *cpu, *app_arch;
   const char * const * langs;
-  char *str_os, *str_native_arch, *str_app_arch, *proc_file;
+  char *str_os, *str_app_arch, *proc_file;
   char **lines;
-  int i, app_bs, native_bs;
+  int i, app_bs;
   enum OS_TYPES e_os;
 
   /* CPU info variables */
   GError *error;
-  char *model_name, *vendor_id, *cpu_family;
-  int  no_cores=0, length, no_proc=0;
+  char *model_name=NULL, *vendor_id=NULL, *cpu_family=NULL;
+  int  no_cores=0, no_proc=0;
+
+  /* Temp var */
+  char **t, *p1, *p2;
+
+  gsize length;
   xmlnode *model_name_xml, *vendor_id_xml, *cpu_family_xml, *no_cores_xml, \
     *no_proc_xml;
 
@@ -127,10 +132,13 @@ get_cpuinfo_xml(){
 
     case WINDOWS:
       str_os = g_strdup("WINDOWS");
+      break;
     case APPLE:
       str_os = g_strdup("APPLE");
+      break;
     case UNIX:
       str_os = g_strdup("UNIX");
+      break;
 
   }
 
@@ -154,8 +162,6 @@ get_cpuinfo_xml(){
 #ifdef __unix__
 
   /* Read the contents */
-  proc_file = (char *)malloc(4096*sizeof(char));
-  proc_file[0] = '\0';
   g_file_get_contents("/proc/cpuinfo", &proc_file, &length, &error);
 
   /* Split it into lines */
@@ -174,11 +180,11 @@ get_cpuinfo_xml(){
     purple_debug_info("STATS", "CPUINFO: %s\n", lines[i]);
 
     /* Create parts */
-    char **t = g_strsplit(lines[i], ":", -1);
+    t = g_strsplit(lines[i], ":", -1);
 
     if(t[0] && t[1]){
 
-      char *p1 = g_strstrip(t[0]), *p2 = g_strstrip(t[1]);
+      p1 = g_strstrip(t[0]), p2 = g_strstrip(t[1]);
 
       if(!g_strcmp0(p1, "cpu family"))
         cpu_family = p2;
@@ -261,7 +267,7 @@ md5(const guchar *str)
         context = purple_cipher_context_new_by_name("md5", NULL);
         g_return_val_if_fail(context != NULL, NULL);
 
-        purple_cipher_context_append(context, str, strlen(str));
+        purple_cipher_context_append(context, str, strlen((char*)str));
 
         if (!purple_cipher_context_digest_to_str(context, sizeof(digest), digest, NULL))
                 return NULL;
@@ -271,19 +277,20 @@ md5(const guchar *str)
         return digest;
 }
 
-static gchar *
-get_acc_id(char *username, char *prpl_id){
+static char *
+get_acc_id(const char *username, const char *prpl_id){
 
   /* Generates a id from username and prpl_id */
 
-  char *id = (char *)malloc(500*sizeof(char));
+  char *id;
 
-  id[0] = '\0';
+  id = g_new0(char, 500);
+
   strcat(id, username);
   strcat(id, "-");
   strcat(id, prpl_id);
 
-  return md5(id);
+  return (char *)md5((const guchar *)id);
 
 }
 
@@ -296,10 +303,10 @@ acc_sign_on_event(PurpleAccount *account
    * 1.1 If no, then add the account to the list of accounts used
    */
 
-  char *username, *protocol, *data;
+  const char *username, *protocol, *data;
   char *id;
 
-  xmlnode *acc, *u_node, *p_node;
+  xmlnode *acc, *p_node;
   username = purple_account_get_username(account);
   protocol = purple_account_get_protocol_id(account);
 
@@ -338,7 +345,7 @@ plugin_load_event(PurplePlugin *plugin){
    */
 
   const char *plugin_id, *data;
-  xmlnode *plugin_xml, *p_id;
+  xmlnode *plugin_xml;
   PurplePluginType plugin_type;
 
   plugin_id = purple_plugin_get_id(plugin);
@@ -381,17 +388,18 @@ init_stats(){
 
   /* GHashTableIter *iter; */
   GList *loaded_plugins;
-  const gchar *file_contents, *filename;
-  int length;
+  const gchar *filename;
+  gchar *file_contents;
+  const char *id_node;
+  gsize length;
   GError *error = NULL;
-  xmlnode *stats_acc_xml, *stats_plugins_xml;
-  xmlnode *start, *id_node;
+  xmlnode *stats_acc_xml, *stats_plugins_xml, *root, *start;
 
   /* Load the xml */
   filename = g_build_filename(purple_user_dir(), "stats.xml", NULL);
   g_file_get_contents(filename, &file_contents, &length, &error);
   purple_debug_info("STATS", "%s", file_contents);
-  xmlnode *root = xmlnode_from_str(file_contents, -1);
+  root = xmlnode_from_str(file_contents, -1);
 
   stats_acc_ht = g_hash_table_new(g_str_hash, g_str_equal);
   stats_plugins_ht = g_hash_table_new(g_str_hash, g_str_equal);
@@ -423,10 +431,10 @@ init_stats(){
 
     for(;start;start = xmlnode_get_next_twin(start)){
 
-      id_node = xmlnode_get_attrib(start, "id");
+      id_node = xmlnode_get_attrib((const xmlnode *)start, "id");
 
       purple_debug_info("STATS","%s %s", id_node, xmlnode_to_formatted_str(start, NULL));
-      g_hash_table_insert(stats_acc_ht, (char *)id_node,
+      g_hash_table_insert(stats_acc_ht, (gpointer)id_node,
           (char *)xmlnode_to_formatted_str(start, NULL));
 
     }
@@ -434,9 +442,9 @@ init_stats(){
 
     for(;start;start = xmlnode_get_next_twin(start)){
 
-      id_node = xmlnode_get_attrib(start, "id");
+      id_node = xmlnode_get_attrib((const xmlnode *)start, "id");
 
-      g_hash_table_insert(stats_plugins_ht, (char *)(id_node),
+      g_hash_table_insert(stats_plugins_ht, (gpointer)id_node,
           (char *)xmlnode_to_formatted_str(start, NULL));
 
     }


More information about the Commits mailing list