/soc/2012/sanket/statscollector-2.x.y: f2148b32b3b2: Remove warn...

Sanket Agarwal sanket at soc.pidgin.im
Tue Jul 10 00:36:22 EDT 2012


Changeset: f2148b32b3b2df842086d2719b93ba11d4fdad31
Author:	 Sanket Agarwal <sanket at soc.pidgin.im>
Date:	 2012-05-17 06:30 +0000
Branch:	 soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/f2148b32b3b2

Description:

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

diffstat:

 pidgin/plugins/statscollector.c |  64 +++++++++++++++++++++++-----------------
 1 files changed, 36 insertions(+), 28 deletions(-)

diffs (183 lines):

diff --git a/pidgin/plugins/statscollector.c b/pidgin/plugins/statscollector.c
--- a/pidgin/plugins/statscollector.c
+++ b/pidgin/plugins/statscollector.c
@@ -33,7 +33,7 @@
    * 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 @@
 
   /* 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 @@
 
     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 @@
 #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 @@
     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 @@
         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 @@
         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 @@
    * 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 @@
    */
 
   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 @@
 
   /* 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 @@
 
     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 @@
 
     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