Remove weird use of dup functions to allocate new structs

Sun, 13 Mar 2022 21:59:38 -0500

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Sun, 13 Mar 2022 21:59:38 -0500
changeset 41287
dd84ced2309c
parent 41286
a0f2d660128d
child 41288
600e7b4219de

Remove weird use of dup functions to allocate new structs

libpurple/protocols/facebook/api.c file | annotate | diff | comparison | revisions
libpurple/protocols/facebook/api.h file | annotate | diff | comparison | revisions
libpurple/protocols/facebook/facebook.c file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/facebook/api.c	Sat Mar 12 23:05:01 2022 -0600
+++ b/libpurple/protocols/facebook/api.c	Sun Mar 13 21:59:38 2022 -0500
@@ -1706,7 +1706,7 @@
 
 	fb_json_values_update(values, &err);
 
-	event = fb_api_event_dup(NULL, FALSE);
+	event = g_new0(FbApiEvent, 1);
 	event->type = type;
 	event->tid = fb_json_values_next_int(values, 0);
 	event->uid = fb_json_values_next_int(values, 0);
@@ -1785,7 +1785,7 @@
 		FB_API_TCHK(id == 2);
 		FB_API_TCHK(fb_thrift_read_i32(thft, &i32));
 
-		api_presence = fb_api_presence_dup(NULL);
+		api_presence = g_new0(FbApiPresence, 1);
 		api_presence->uid = i64;
 		api_presence->active = i32 != 0;
 		*presences = g_slist_prepend(*presences, api_presence);
@@ -2267,7 +2267,7 @@
 			continue;
 		}
 
-		user = fb_api_user_dup(NULL, FALSE);
+		user = g_new0(FbApiUser, 1);
 		user->uid = uid;
 		user->name = fb_json_values_next_str_dup(values, NULL);
 		user->icon = fb_json_values_next_str_dup(values, NULL);
@@ -2534,7 +2534,7 @@
 	g_return_if_fail(text != NULL);
 	priv = api->priv;
 
-	msg = fb_api_message_dup(NULL, FALSE);
+	msg = g_new0(FbApiMessage, 1);
 	msg->text = g_strdup(text);
 
 	if (thread) {
@@ -2959,7 +2959,7 @@
 		num_users++;
 
 		if (uid != priv->uid) {
-			user = fb_api_user_dup(NULL, FALSE);
+			user = g_new0(FbApiUser, 1);
 			user->uid = uid;
 			user->name = fb_json_values_next_str_dup(values, NULL);
 			thrd->users = g_slist_prepend(thrd->users, user);
@@ -3266,7 +3266,7 @@
 	FbApiEvent *ret;
 
 	if (event == NULL) {
-		return g_new0(FbApiEvent, 1);
+		return NULL;
 	}
 
 	ret = g_memdup2(event, sizeof *event);
@@ -3305,7 +3305,7 @@
 	FbApiMessage *ret;
 
 	if (msg == NULL) {
-		return g_new0(FbApiMessage, 1);
+		return NULL;
 	}
 
 	ret = g_memdup2(msg, sizeof *msg);
@@ -3341,10 +3341,6 @@
 FbApiPresence *
 fb_api_presence_dup(const FbApiPresence *presence)
 {
-	if (presence == NULL) {
-		return g_new0(FbApiPresence, 1);
-	}
-
 	return g_memdup2(presence, sizeof *presence);
 }
 
@@ -3371,7 +3367,7 @@
 	GSList *l;
 
 	if (thrd == NULL) {
-		return g_new0(FbApiThread, 1);
+		return NULL;
 	}
 
 	ret = g_memdup2(thrd, sizeof *thrd);
@@ -3417,10 +3413,6 @@
 FbApiTyping *
 fb_api_typing_dup(const FbApiTyping *typg)
 {
-	if (typg == NULL) {
-		return g_new0(FbApiTyping, 1);
-	}
-
 	return g_memdup2(typg, sizeof *typg);
 }
 
@@ -3445,7 +3437,7 @@
 	FbApiUser *ret;
 
 	if (user == NULL) {
-		return g_new0(FbApiUser, 1);
+		return NULL;
 	}
 
 	ret = g_memdup2(user, sizeof *user);
--- a/libpurple/protocols/facebook/api.h	Sat Mar 12 23:05:01 2022 -0600
+++ b/libpurple/protocols/facebook/api.h	Sun Mar 13 21:59:38 2022 -0500
@@ -766,9 +766,8 @@
  * @event: The #FbApiEvent or #NULL.
  * @deep: #TRUE to duplicate allocated data, otherwise #FALSE.
  *
- * Duplicates an #FbApiEvent. If @event is #NULL, a new zero filled
- * #FbApiEvent is returned. The returned #FbApiEvent should be freed
- * with #fb_api_event_free() when no longer needed.
+ * Duplicates an #FbApiEvent. The returned #FbApiEvent should be freed with
+ * #fb_api_event_free() when no longer needed.
  *
  * Returns: The new #FbApiEvent.
  */
@@ -799,9 +798,8 @@
  * @msg: The #FbApiMessage or #NULL.
  * @deep: #TRUE to duplicate allocated data, otherwise #FALSE.
  *
- * Duplicates an #FbApiMessage. If @msg is #NULL, a new zero filled
- * #FbApiMessage is returned. The returned #FbApiMessage should be
- * freed with #fb_api_message_free() when no longer needed.
+ * Duplicates an #FbApiMessage. The returned #FbApiMessage should be freed with
+ * #fb_api_message_free() when no longer needed.
  *
  * Returns: The new #FbApiMessage.
  */
@@ -831,9 +829,8 @@
  * fb_api_presence_dup:
  * @presence: The #FbApiPresence or %NULL.
  *
- * Duplicates an #FbApiPresence. If @presence is %NULL, a new zero filled
- * #FbApiPresence is returned. The returned #FbApiPresence should be freed with
- * #fb_api_presence_free() when no longer needed.
+ * Duplicates an #FbApiPresence. The returned #FbApiPresence should be freed
+ * with #fb_api_presence_free() when no longer needed.
  *
  * Returns: The new #FbApiPresence.
  */
@@ -863,9 +860,8 @@
  * @thrd: The #FbApiThread or #NULL.
  * @deep: #TRUE to duplicate allocated data, otherwise #FALSE.
  *
- * Duplicates an #FbApiThread. If @thrd is #NULL, a new zero filled
- * #FbApiThread is returned. The returned #FbApiThread should be freed
- * with #fb_api_thread_free() when no longer needed.
+ * Duplicates an #FbApiThread. The returned #FbApiThread should be freed with
+ * #fb_api_thread_free() when no longer needed.
  *
  * Returns: The new #FbApiThread.
  */
@@ -895,9 +891,8 @@
  * fb_api_typing_dup:
  * @typg: The #FbApiTyping or #NULL.
  *
- * Duplicates an #FbApiTyping. If @typg is #NULL, a new zero filled
- * #FbApiTyping is returned. The returned #FbApiTyping should be freed
- * with #fb_api_typing_free() when no longer needed.
+ * Duplicates an #FbApiTyping. The returned #FbApiTyping should be freed with
+ * #fb_api_typing_free() when no longer needed.
  *
  * Returns: The new #FbApiTyping.
  */
@@ -927,8 +922,7 @@
  * @user: The #FbApiUser or #NULL.
  * @deep: #TRUE to duplicate allocated data, otherwise #FALSE.
  *
- * Duplicates an #FbApiUser. If @user is #NULL, a new zero filled
- * #FbApiUser is returned. The returned #FbApiUser should be freed with
+ * Duplicates an #FbApiUser. The returned #FbApiUser should be freed with
  * #fb_api_user_free() when no longer needed.
  *
  * Returns: The new #FbApiUser.
--- a/libpurple/protocols/facebook/facebook.c	Sat Mar 12 23:05:01 2022 -0600
+++ b/libpurple/protocols/facebook/facebook.c	Sun Mar 13 21:59:38 2022 -0500
@@ -425,7 +425,7 @@
 		case FB_API_EVENT_TYPE_THREAD_USER_ADDED:
 			if (purple_blist_find_buddy(acct, uid) == NULL) {
 				if (event->text) {
-					FbApiUser *user = fb_api_user_dup(NULL, FALSE);
+					FbApiUser *user = g_new0(FbApiUser, 1);
 					user->uid = event->uid;
 					user->name = g_strdup(event->text);
 

mercurial