From: <rl...@us...> - 2006-09-26 17:38:16
|
Revision: 17356 http://svn.sourceforge.net/gaim/?rev=17356&view=rev Author: rlaager Date: 2006-09-26 10:38:09 -0700 (Tue, 26 Sep 2006) Log Message: ----------- After the comments on gaim-devel about 'bad' code, I looked into the function referenced. It appears that yahoo_buddy_icon_upload_connected() is only called as a callback. It's registered from yahoo_buddy_icon_upload(). yahoo_buddy_icon_upload() is only called twice. In neither case can a NULL make it down to yahoo_buddy_icon_upload_connected(). As this is an exceptional case rather than a normal one, a g_return_if_fail() is more appropriate. That adds logging, makes the intent clearer, and will help the Coverity software detect violations of this assumption. Modified Paths: -------------- trunk/libgaim/protocols/yahoo/yahoo_picture.c Modified: trunk/libgaim/protocols/yahoo/yahoo_picture.c =================================================================== --- trunk/libgaim/protocols/yahoo/yahoo_picture.c 2006-09-26 17:24:45 UTC (rev 17355) +++ trunk/libgaim/protocols/yahoo/yahoo_picture.c 2006-09-26 17:38:09 UTC (rev 17356) @@ -438,8 +438,7 @@ GaimAccount *account; struct yahoo_data *yd; - if (!d) - return; + g_return_if_fail(d != NULL); gc = d->gc; account = gaim_connection_get_account(gc); @@ -500,6 +499,8 @@ GaimAccount *account = gaim_connection_get_account(gc); struct yahoo_data *yd = gc->proto_data; + g_return_if_fail(d != NULL); + if (yd->jp) { if (gaim_proxy_connect(account, gaim_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST), gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-11-16 20:07:30
|
Revision: 17759 http://svn.sourceforge.net/gaim/?rev=17759&view=rev Author: thekingant Date: 2006-11-16 12:07:19 -0800 (Thu, 16 Nov 2006) Log Message: ----------- This call is not needed--the string is initialized to the correct size. Modified Paths: -------------- trunk/libgaim/protocols/yahoo/yahoo_picture.c Modified: trunk/libgaim/protocols/yahoo/yahoo_picture.c =================================================================== --- trunk/libgaim/protocols/yahoo/yahoo_picture.c 2006-11-16 04:58:40 UTC (rev 17758) +++ trunk/libgaim/protocols/yahoo/yahoo_picture.c 2006-11-16 20:07:19 UTC (rev 17759) @@ -561,7 +561,6 @@ int expire = gaim_account_get_int(account, YAHOO_PICEXPIRE_SETTING, 0); const char *oldurl = gaim_account_get_string(account, YAHOO_PICURL_SETTING, NULL); - g_string_set_size(s, st.st_size); len = fread(s->str, 1, st.st_size, file); fclose(file); g_string_set_size(s, len); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-12-11 22:15:02
|
Revision: 17964 http://svn.sourceforge.net/gaim/?rev=17964&view=rev Author: thekingant Date: 2006-12-11 14:03:18 -0800 (Mon, 11 Dec 2006) Log Message: ----------- Minor cleanup. No functionality change. Someone at work asked me if I just sit around and audit code all day. Modified Paths: -------------- trunk/libgaim/protocols/yahoo/yahoo_picture.c Modified: trunk/libgaim/protocols/yahoo/yahoo_picture.c =================================================================== --- trunk/libgaim/protocols/yahoo/yahoo_picture.c 2006-12-11 19:44:35 UTC (rev 17963) +++ trunk/libgaim/protocols/yahoo/yahoo_picture.c 2006-12-11 22:03:18 UTC (rev 17964) @@ -345,7 +345,7 @@ static void yahoo_send_picture_update_foreach(gpointer key, gpointer value, gpointer data) { - char *who = key; + const char *who = key; YahooFriend *f = value; struct yspufe *d = data; @@ -438,8 +438,6 @@ GaimAccount *account; struct yahoo_data *yd; - g_return_if_fail(d != NULL); - gc = d->gc; account = gaim_connection_get_account(gc); yd = gc->proto_data; @@ -448,7 +446,7 @@ yd->buddy_icon_connect_data = NULL; if (source < 0) { - gaim_debug_error("yahoo", "Buddy icon upload failed, no file desc.\n"); + gaim_debug_error("yahoo", "Buddy icon upload failed: %s\n", error_message); yahoo_buddy_icon_upload_data_free(d); return; } @@ -500,36 +498,23 @@ { GaimAccount *account = gaim_connection_get_account(gc); struct yahoo_data *yd = gc->proto_data; - GaimProxyConnectData *connect_data = NULL; - g_return_if_fail(d != NULL); - - if (yd->buddy_icon_connect_data) { + if (yd->buddy_icon_connect_data != NULL) { /* Cancel any in-progress buddy icon upload */ gaim_proxy_connect_cancel(yd->buddy_icon_connect_data); yd->buddy_icon_connect_data = NULL; } - if (yd->jp) { - if ((connect_data = gaim_proxy_connect(NULL, account, gaim_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST), - gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), - yahoo_buddy_icon_upload_connected, d)) == NULL) - { - gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n"); - yahoo_buddy_icon_upload_data_free(d); - } - } else { - if ((connect_data = gaim_proxy_connect(NULL, account, gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST), - gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), - yahoo_buddy_icon_upload_connected, d)) == NULL) - { - gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n"); - yahoo_buddy_icon_upload_data_free(d); - } - } + yd->buddy_icon_connect_data = gaim_proxy_connect(NULL, account, + yd->jp ? gaim_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST) + : gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST), + gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), + yahoo_buddy_icon_upload_connected, d); - if (connect_data) { - yd->buddy_icon_connect_data = connect_data; + if (yd->buddy_icon_connect_data == NULL) + { + gaim_debug_error("yahoo", "Uploading our buddy icon failed to connect.\n"); + yahoo_buddy_icon_upload_data_free(d); } } @@ -537,61 +522,56 @@ { struct yahoo_data *yd = gc->proto_data; GaimAccount *account = gc->account; - FILE *file; - struct stat st; + gchar *icondata; + gsize len; + GError *error = NULL; if (iconfile == NULL) { - if (yd->picture_url) - g_free(yd->picture_url); + g_free(yd->picture_url); yd->picture_url = NULL; gaim_account_set_string(account, YAHOO_PICURL_SETTING, NULL); gaim_account_set_int(account, YAHOO_PICCKSUM_SETTING, 0); gaim_account_set_int(account, YAHOO_PICEXPIRE_SETTING, 0); if (yd->logged_in) + /* Tell everyone we ain't got one no more */ yahoo_send_picture_update(gc, 0); - /* TODO: check if we're connected and tell everyone we ain't not one no more */ - } else if (!g_stat(iconfile, &st)) { - file = g_fopen(iconfile, "rb"); - if (file) { - GString *s = g_string_sized_new(st.st_size); - size_t len; - struct yahoo_buddy_icon_upload_data *d; - int oldcksum = gaim_account_get_int(account, YAHOO_PICCKSUM_SETTING, 0); - int expire = gaim_account_get_int(account, YAHOO_PICEXPIRE_SETTING, 0); - const char *oldurl = gaim_account_get_string(account, YAHOO_PICURL_SETTING, NULL); - len = fread(s->str, 1, st.st_size, file); - fclose(file); - g_string_set_size(s, len); - yd->picture_checksum = g_string_hash(s); + } else if (g_file_get_contents(iconfile, &icondata, &len, &error)) { + GString *s = g_string_new_len(icondata, len); + struct yahoo_buddy_icon_upload_data *d; + int oldcksum = gaim_account_get_int(account, YAHOO_PICCKSUM_SETTING, 0); + int expire = gaim_account_get_int(account, YAHOO_PICEXPIRE_SETTING, 0); + const char *oldurl = gaim_account_get_string(account, YAHOO_PICURL_SETTING, NULL); - if ((yd->picture_checksum == oldcksum) && (expire > (time(NULL) + 60*60*24)) && - oldcksum && expire && oldurl) { - gaim_debug_misc("yahoo", "buddy icon is up to date. Not reuploading.\n"); - g_string_free(s, TRUE); - if (yd->picture_url) - g_free(yd->picture_url); - yd->picture_url = g_strdup(oldurl); - return; - } + yd->picture_checksum = g_string_hash(s); - d = g_new0(struct yahoo_buddy_icon_upload_data, 1); - d->gc = gc; - d->str = s; - d->fd = -1; - d->filename = g_strdup(iconfile); + if ((yd->picture_checksum == oldcksum) && + (expire > (time(NULL) + 60*60*24)) && oldurl) + { + gaim_debug_misc("yahoo", "buddy icon is up to date. Not reuploading.\n"); + g_string_free(s, TRUE); + g_free(yd->picture_url); + yd->picture_url = g_strdup(oldurl); + return; + } - if (!yd->logged_in) { - yd->picture_upload_todo = d; - return; - } + d = g_new0(struct yahoo_buddy_icon_upload_data, 1); + d->gc = gc; + d->str = s; + d->fd = -1; + d->filename = g_strdup(iconfile); - yahoo_buddy_icon_upload(gc, d); - } else - gaim_debug_error("yahoo", - "Can't open buddy icon file!\n"); + if (!yd->logged_in) { + yd->picture_upload_todo = d; + return; + } + + yahoo_buddy_icon_upload(gc, d); + } else gaim_debug_error("yahoo", - "Can't stat buddy icon file!\n"); -} + "Could not read buddy icon file '%s': %s\n", + iconfile, error->message); + g_error_free(error); + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <the...@us...> - 2006-12-12 08:56:15
|
Revision: 17972 http://svn.sourceforge.net/gaim/?rev=17972&view=rev Author: thekingant Date: 2006-12-12 00:52:46 -0800 (Tue, 12 Dec 2006) Log Message: ----------- I left off a brace. My bad! Modified Paths: -------------- trunk/libgaim/protocols/yahoo/yahoo_picture.c Modified: trunk/libgaim/protocols/yahoo/yahoo_picture.c =================================================================== --- trunk/libgaim/protocols/yahoo/yahoo_picture.c 2006-12-12 08:46:07 UTC (rev 17971) +++ trunk/libgaim/protocols/yahoo/yahoo_picture.c 2006-12-12 08:52:46 UTC (rev 17972) @@ -569,9 +569,10 @@ yahoo_buddy_icon_upload(gc, d); - } else + } else { gaim_debug_error("yahoo", "Could not read buddy icon file '%s': %s\n", iconfile, error->message); g_error_free(error); } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |