/soc/2015/mmcc/main: 11e67b8fb424: Print time_t values as gint64...

Michael McConville mmcconville at mykolab.com
Thu Aug 13 19:29:28 EDT 2015


Changeset: 11e67b8fb424dca5c61c12a1082fe6ab62886672
Author:	 Michael McConville <mmcconville at mykolab.com>
Date:	 2015-08-13 19:26 -0400
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/mmcc/main/rev/11e67b8fb424

Description:

Print time_t values as gint64 to be safe across all platforms and silence
compiler warnings. We should probably replace time_t where possible to
prevent needless casts.

diffstat:

 finch/gntprefs.c                     |   2 +-
 libpurple/nat-pmp.c                  |   4 ++--
 libpurple/protocols/gg/avatar.c      |  22 ++++++++++++----------
 libpurple/protocols/gg/oauth/oauth.c |   3 ++-
 libpurple/protocols/gg/pubdir-prpl.c |   6 +++---
 libpurple/protocols/irc/cmds.c       |   8 +++++---
 libpurple/protocols/irc/msgs.c       |   3 ++-
 libpurple/protocols/irc/parse.c      |   4 ++--
 libpurple/protocols/jabber/iq.c      |   3 ++-
 libpurple/protocols/mxit/login.c     |   8 ++++----
 libpurple/protocols/mxit/markup.c    |   4 ++--
 libpurple/protocols/simple/simple.c  |   3 ++-
 libpurple/savedstatuses.c            |   4 ++--
 13 files changed, 41 insertions(+), 33 deletions(-)

diffs (261 lines):

diff --git a/finch/gntprefs.c b/finch/gntprefs.c
--- a/finch/gntprefs.c
+++ b/finch/gntprefs.c
@@ -96,7 +96,7 @@ get_status_titles(void)
 		char *str;
 		if (purple_savedstatus_is_transient(iter->data))
 			continue;
-		str = g_strdup_printf("%ld", purple_savedstatus_get_creation_time(iter->data));
+		str = g_strdup_printf("%" G_GINT64_FORMAT, (gint64)purple_savedstatus_get_creation_time(iter->data));
 		list = g_list_append(list, (char*)purple_savedstatus_get_title(iter->data));
 		list = g_list_append(list, str);
 		pref_request.freestrings = g_list_prepend(pref_request.freestrings, str);
diff --git a/libpurple/nat-pmp.c b/libpurple/nat-pmp.c
--- a/libpurple/nat-pmp.c
+++ b/libpurple/nat-pmp.c
@@ -319,7 +319,7 @@ purple_pmp_get_public_ip()
 	 */
 #ifdef PMP_DEBUG
 	purple_debug_info("nat-pmp", "Attempting to retrieve the public ip address for the NAT device at: %s\n", inet_ntoa(gateway->sin_addr));
-	purple_debug_info("nat-pmp", "\tTimeout: %ds %dus\n", req_timeout.tv_sec, req_timeout.tv_usec);
+	purple_debug_info("nat-pmp", "\tTimeout: %" G_GINT64_FORMAT "s %dus\n", (gint64)req_timeout.tv_sec, req_timeout.tv_usec);
 #endif
 
 	/* TODO: Non-blocking! */
@@ -440,7 +440,7 @@ purple_pmp_create_map(PurplePmpType type
 	 */
 #ifdef PMP_DEBUG
 	purple_debug_info("nat-pmp", "Attempting to create a NAT-PMP mapping the private port %d, and the public port %d\n", privateport, publicport);
-	purple_debug_info("nat-pmp", "\tTimeout: %ds %dus\n", req_timeout.tv_sec, req_timeout.tv_usec);
+	purple_debug_info("nat-pmp", "\tTimeout: %" G_GINT64_FORMAT "s %dus\n", (gint64)req_timeout.tv_sec, req_timeout.tv_usec);
 #endif
 
 	/* TODO: Non-blocking! */
diff --git a/libpurple/protocols/gg/avatar.c b/libpurple/protocols/gg/avatar.c
--- a/libpurple/protocols/gg/avatar.c
+++ b/libpurple/protocols/gg/avatar.c
@@ -153,8 +153,8 @@ void ggp_avatar_buddy_update(PurpleConne
 		g_new(ggp_avatar_buddy_update_req, 1); /* TODO: leak? */
 
 	if (purple_debug_is_verbose()) {
-		purple_debug_misc("gg", "ggp_avatar_buddy_update(%p, %u, %lu)\n", gc,
-			uin, timestamp);
+		purple_debug_misc("gg", "ggp_avatar_buddy_update(%p, %u, %" G_GINT64_FORMAT ")\n", gc,
+			uin, (gint64)timestamp);
 	}
 
 	pending_update->uin = uin;
@@ -220,8 +220,9 @@ static gboolean ggp_avatar_buddy_update_
 		if (purple_debug_is_verbose()) {
 			purple_debug_misc("gg",
 				"ggp_avatar_buddy_update_next(%p): "
-				"%u have up to date avatar with ts=%lu\n", gc,
-				pending_update->uin, pending_update->timestamp);
+				"%u have up to date avatar with ts=%"
+				G_GINT64_FORMAT "\n", gc,
+				pending_update->uin, (gint64)pending_update->timestamp);
 		}
 		return FALSE;
 	}
@@ -229,8 +230,9 @@ static gboolean ggp_avatar_buddy_update_
 		purple_debug_warning("gg",
 			"ggp_avatar_buddy_update_next(%p): "
 			"saved timestamp for %u is newer than received "
-			"(%lu > %lu)\n", gc, pending_update->uin, old_timestamp,
-			pending_update->timestamp);
+			"(%" G_GINT64_FORMAT " > %" G_GINT64_FORMAT ")\n",
+			gc, pending_update->uin,
+			(gint64)old_timestamp, (gint64)pending_update->timestamp);
 	}
 
 	purple_debug_info("gg",
@@ -290,15 +292,15 @@ static void ggp_avatar_buddy_update_rece
 		return;
 	}
 
-	g_snprintf(timestamp_str, sizeof(timestamp_str), "%lu",
-		pending_update->timestamp);
+	g_snprintf(timestamp_str, sizeof(timestamp_str), "%" G_GINT64_FORMAT,
+		(gint64)pending_update->timestamp);
 	got_data = purple_http_response_get_data(response, &got_len);
 	purple_buddy_icons_set_for_user(account, purple_buddy_get_name(buddy),
 		g_memdup(got_data, got_len), got_len, timestamp_str);
 
 	purple_debug_info("gg", "ggp_avatar_buddy_update_received: "
-		"got avatar for buddy %u [ts=%lu]\n", pending_update->uin,
-		pending_update->timestamp);
+		"got avatar for buddy %u [ts=%" G_GINT64_FORMAT "]\n",
+		pending_update->uin, (gint64)pending_update->timestamp);
 	g_free(pending_update);
 }
 
diff --git a/libpurple/protocols/gg/oauth/oauth.c b/libpurple/protocols/gg/oauth/oauth.c
--- a/libpurple/protocols/gg/oauth/oauth.c
+++ b/libpurple/protocols/gg/oauth/oauth.c
@@ -112,7 +112,8 @@ gg_oauth_generate_header(const char *met
 	}
 
 	if (gg_oauth_static_timestamp == NULL)
-		snprintf(timestamp, sizeof(timestamp), "%ld", time(NULL));
+		snprintf(timestamp, sizeof(timestamp), "%" G_GINT64_FORMAT,
+				(gint64)time(NULL));
 	else {
 		strncpy(timestamp, gg_oauth_static_timestamp, sizeof(timestamp) - 1);
 		timestamp[sizeof(timestamp) - 1] = 0;
diff --git a/libpurple/protocols/gg/pubdir-prpl.c b/libpurple/protocols/gg/pubdir-prpl.c
--- a/libpurple/protocols/gg/pubdir-prpl.c
+++ b/libpurple/protocols/gg/pubdir-prpl.c
@@ -332,10 +332,10 @@ static void ggp_pubdir_got_data(PurpleHt
 			purple_debug_misc("gg", "ggp_pubdir_got_data: [uin:%d] "
 				"[label:%s] [nick:%s] [first name:%s] "
 				"[last name:%s] [city:%s] [gender:%d] [age:%d] "
-				"[birth:%lu]\n", record->uin, record->label,
-				record->nickname, record->first_name,
+				"[birth:%" G_GINT64_FORMAT "]\n", record->uin,
+				record->label, record->nickname, record->first_name,
 				record->last_name, record->city, record->gender,
-				record->age, record->birth);
+				record->age, (gint64)record->birth);
 		}
 
 		g_free(city);
diff --git a/libpurple/protocols/irc/cmds.c b/libpurple/protocols/irc/cmds.c
--- a/libpurple/protocols/irc/cmds.c
+++ b/libpurple/protocols/irc/cmds.c
@@ -402,15 +402,17 @@ int irc_cmd_ping(struct irc_conn *irc, c
 	if (args && args[0]) {
 		if (irc_ischannel(args[0]))
 			return 0;
-		stamp = g_strdup_printf("\001PING %lu\001", time(NULL));
+		stamp = g_strdup_printf("\001PING %" G_GINT64_FORMAT "\001",
+				(gint64)time(NULL));
 		buf = irc_format(irc, "vn:", "PRIVMSG", args[0], stamp);
 		g_free(stamp);
 	} else if (target) {
-		stamp = g_strdup_printf("%s %lu", target, time(NULL));
+		stamp = g_strdup_printf("%s %" G_GINT64_FORMAT, target,
+				(gint64)time(NULL));
 		buf = irc_format(irc, "v:", "PING", stamp);
 		g_free(stamp);
 	} else {
-		stamp = g_strdup_printf("%lu", time(NULL));
+		stamp = g_strdup_printf("%" G_GINT64_FORMAT, (gint64)time(NULL));
 		buf = irc_format(irc, "vv", "PING", stamp);
 		g_free(stamp);
 	}
diff --git a/libpurple/protocols/irc/msgs.c b/libpurple/protocols/irc/msgs.c
--- a/libpurple/protocols/irc/msgs.c
+++ b/libpurple/protocols/irc/msgs.c
@@ -1257,7 +1257,8 @@ void irc_msg_pong(struct irc_conn *irc, 
 	if (sscanf(parts[1], "%lu", &oldstamp) != 1) {
 		msg = g_strdup(_("Error: invalid PONG from server"));
 	} else {
-		msg = g_strdup_printf(_("PING reply -- Lag: %lu seconds"), time(NULL) - oldstamp);
+		msg = g_strdup_printf(_("PING reply -- Lag: %" G_GINT64_FORMAT " seconds"),
+				(gint64)(time(NULL) - oldstamp));
 	}
 
 	convo = purple_conversations_find_with_account(parts[0], irc->account);
diff --git a/libpurple/protocols/irc/parse.c b/libpurple/protocols/irc/parse.c
--- a/libpurple/protocols/irc/parse.c
+++ b/libpurple/protocols/irc/parse.c
@@ -581,9 +581,9 @@ char *irc_parse_ctcp(struct irc_conn *ir
 			gc = purple_account_get_connection(irc->account);
 			if (!gc)
 				return NULL;
-			/* TODO: Should this read in the timestamp as a double? */
 			if (sscanf(cur, "PING %lu", &timestamp) == 1) {
-				buf = g_strdup_printf(_("Reply time from %s: %lu seconds"), from, time(NULL) - timestamp);
+				buf = g_strdup_printf(_("Reply time from %s: %" G_GINT64_FORMAT " seconds"),
+						from, (gint64)(time(NULL) - timestamp));
 				purple_notify_info(gc, _("PONG"),
 					_("CTCP PING reply"), buf,
 					purple_request_cpar_from_connection(gc));
diff --git a/libpurple/protocols/jabber/iq.c b/libpurple/protocols/jabber/iq.c
--- a/libpurple/protocols/jabber/iq.c
+++ b/libpurple/protocols/jabber/iq.c
@@ -174,7 +174,8 @@ static void jabber_iq_last_parse(JabberS
 
 		query = purple_xmlnode_get_child(iq->node, "query");
 
-		idle_time = g_strdup_printf("%ld", js->idle ? time(NULL) - js->idle : 0);
+		idle_time = g_strdup_printf("%" G_GINT64_FORMAT,
+				js->idle ? (gint64)(time(NULL) - js->idle) : 0);
 		purple_xmlnode_set_attrib(query, "seconds", idle_time);
 		g_free(idle_time);
 
diff --git a/libpurple/protocols/mxit/login.c b/libpurple/protocols/mxit/login.c
--- a/libpurple/protocols/mxit/login.c
+++ b/libpurple/protocols/mxit/login.c
@@ -559,7 +559,7 @@ static void mxit_cb_captcha_ok( PurpleCo
 	req = purple_http_request_new(NULL);
 	purple_http_request_set_url_printf(req, "%s?type=getpid&sessionid=%s&"
 		"login=%s&ver=%i.%i.%i&clientid=%s&cat=%s&chalresp=%s&cc=%s&"
-		"loc=%s&path=%i&brand=%s&model=%s&h=%i&w=%i&ts=%li",
+		"loc=%s&path=%i&brand=%s&model=%s&h=%i&w=%i&ts=%" G_GINT64_FORMAT,
 		session->logindata->wapserver, session->logindata->sessionid,
 		purple_url_encode(purple_account_get_username(session->acc)),
 		PURPLE_MAJOR_VERSION, PURPLE_MINOR_VERSION,
@@ -568,7 +568,7 @@ static void mxit_cb_captcha_ok( PurpleCo
 		session->logindata->locale,
 		(state == MXIT_STATE_REGISTER1) ? 0 : 1, MXIT_CP_PLATFORM,
 		MXIT_CP_OS, MXIT_CAPTCHA_HEIGHT, MXIT_CAPTCHA_WIDTH,
-		time(NULL));
+		(gint64)time(NULL));
 	purple_http_request_header_set(req, "User-Agent", MXIT_HTTP_USERAGENT);
 	purple_http_connection_set_add(session->async_http_reqs,
 		purple_http_request(session->con, req, mxit_cb_clientinfo2,
@@ -739,8 +739,8 @@ get_clientinfo(struct MXitSession* sessi
 	req = purple_http_request_new(NULL);
 	purple_http_request_set_url_printf(req, "%s/res/?type=challenge&"
 		"getcountries=true&getlanguage=true&getimage=true&h=%i&w=%i"
-		"&ts=%li", wapserver, MXIT_CAPTCHA_HEIGHT, MXIT_CAPTCHA_WIDTH,
-		time(NULL));
+		"&ts=%" G_GINT64_FORMAT, wapserver, MXIT_CAPTCHA_HEIGHT,
+		MXIT_CAPTCHA_WIDTH, (gint64)time(NULL));
 	purple_http_request_header_set(req, "User-Agent", MXIT_HTTP_USERAGENT);
 	purple_http_connection_set_add(session->async_http_reqs,
 		purple_http_request(session->con, req, mxit_cb_clientinfo1,
diff --git a/libpurple/protocols/mxit/markup.c b/libpurple/protocols/mxit/markup.c
--- a/libpurple/protocols/mxit/markup.c
+++ b/libpurple/protocols/mxit/markup.c
@@ -650,8 +650,8 @@ static void emoticon_request( struct RXM
 
 	purple_http_connection_set_add(mx->session->async_http_reqs,
 		purple_http_get_printf(mx->session->con, emoticon_returned, mx,
-			"%s/res/?type=emo&mlh=%i&sc=%s&ts=%li", wapserver,
-			MXIT_EMOTICON_SIZE, id, time( NULL ) ));
+			"%s/res/?type=emo&mlh=%i&sc=%s&ts=%" G_GINT64_FORMAT,
+			wapserver, MXIT_EMOTICON_SIZE, id, (gint64)time( NULL ) ));
 }
 
 
diff --git a/libpurple/protocols/simple/simple.c b/libpurple/protocols/simple/simple.c
--- a/libpurple/protocols/simple/simple.c
+++ b/libpurple/protocols/simple/simple.c
@@ -967,7 +967,8 @@ static gboolean resend_timeout(struct si
 	while(tmp) {
 		struct transaction *trans = tmp->data;
 		tmp = tmp->next;
-		purple_debug_info("simple", "have open transaction age: %lu\n", currtime- trans->time);
+		purple_debug_info("simple", "have open transaction age: %" G_GINT64_FORMAT "\n",
+				(gint64)(currtime- trans->time));
 		if((currtime - trans->time > 5) && trans->retries >= 1) {
 			/* TODO 408 */
 		} else {
diff --git a/libpurple/savedstatuses.c b/libpurple/savedstatuses.c
--- a/libpurple/savedstatuses.c
+++ b/libpurple/savedstatuses.c
@@ -280,10 +280,10 @@ status_to_xmlnode(PurpleSavedStatus *sta
 		purple_xmlnode_set_attrib(node, "transient", "true");
 	}
 
-	g_snprintf(buf, sizeof(buf), "%lu", status->creation_time);
+	g_snprintf(buf, sizeof(buf), "%" G_GINT64_FORMAT, (gint64)status->creation_time);
 	purple_xmlnode_set_attrib(node, "created", buf);
 
-	g_snprintf(buf, sizeof(buf), "%lu", status->lastused);
+	g_snprintf(buf, sizeof(buf), "%" G_GINT64_FORMAT, (gint64)status->lastused);
 	purple_xmlnode_set_attrib(node, "lastused", buf);
 
 	g_snprintf(buf, sizeof(buf), "%u", status->usage_count);



More information about the Commits mailing list