Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pidgin/libpurple/glibcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#include <glib.h>

#include <purple.h>

/* glib's definition of g_stat+GStatBuf seems to be broken on mingw64-w32 (and
* possibly other 32-bit windows), so instead of relying on it,
* we'll define our own.
Expand Down Expand Up @@ -136,4 +138,22 @@ static inline void g_queue_free_full(GQueue *queue, GDestroyNotify free_func)
} G_STMT_END
#endif

/* Backport the static inline version of g_memdup2 if we don't have g_memdup2.
* see https://mail.gnome.org/archives/desktop-devel-list/2021-February/msg00000.html
* for more information.
*/
#if !GLIB_CHECK_VERSION(2, 67, 3) && !PURPLE_VERSION_CHECK(2, 14, 2)
static inline gpointer
g_memdup2(gconstpointer mem, gsize byte_size) {
gpointer new_mem = NULL;

if(mem && byte_size != 0) {
new_mem = g_malloc (byte_size);
memcpy (new_mem, mem, byte_size);
}

return new_mem;
}
#endif /* !GLIB_CHECK_VERSION(2, 67, 3) */

#endif /* _GLIBCOMPAT_H_ */
2 changes: 1 addition & 1 deletion pidgin/libpurple/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -2664,7 +2664,7 @@ void purple_http_request_set_contents(PurpleHttpRequest *request,

if (length == -1)
length = strlen(contents);
request->contents = g_memdup(contents, length);
request->contents = g_memdup2(contents, length);
request->contents_length = length;
}

Expand Down
3 changes: 2 additions & 1 deletion pidgin/libpurple/protocols/facebook/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ AM_CPPFLAGS = \
$(PURPLE_CFLAGS) \
$(ZLIB_CFLAGS) \
$(PLUGIN_CFLAGS) \
$(DEBUG_CFLAGS)
$(DEBUG_CFLAGS) \
-DGLIB_DISABLE_DEPRECATION_WARNINGS
12 changes: 6 additions & 6 deletions pidgin/libpurple/protocols/facebook/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3323,7 +3323,7 @@ fb_api_event_dup(const FbApiEvent *event, gboolean deep)
return g_new0(FbApiEvent, 1);
}

ret = g_memdup(event, sizeof *event);
ret = g_memdup2(event, sizeof *event);

if (deep) {
ret->text = g_strdup(event->text);
Expand Down Expand Up @@ -3362,7 +3362,7 @@ fb_api_message_dup(const FbApiMessage *msg, gboolean deep)
return g_new0(FbApiMessage, 1);
}

ret = g_memdup(msg, sizeof *msg);
ret = g_memdup2(msg, sizeof *msg);

if (deep) {
ret->text = g_strdup(msg->text);
Expand Down Expand Up @@ -3399,7 +3399,7 @@ fb_api_presence_dup(const FbApiPresence *pres)
return g_new0(FbApiPresence, 1);
}

return g_memdup(pres, sizeof *pres);
return g_memdup2(pres, sizeof *pres);
}

void
Expand Down Expand Up @@ -3428,7 +3428,7 @@ fb_api_thread_dup(const FbApiThread *thrd, gboolean deep)
return g_new0(FbApiThread, 1);
}

ret = g_memdup(thrd, sizeof *thrd);
ret = g_memdup2(thrd, sizeof *thrd);

if (deep) {
ret->users = NULL;
Expand Down Expand Up @@ -3475,7 +3475,7 @@ fb_api_typing_dup(const FbApiTyping *typg)
return g_new0(FbApiTyping, 1);
}

return g_memdup(typg, sizeof *typg);
return g_memdup2(typg, sizeof *typg);
}

void
Expand All @@ -3502,7 +3502,7 @@ fb_api_user_dup(const FbApiUser *user, gboolean deep)
return g_new0(FbApiUser, 1);
}

ret = g_memdup(user, sizeof *user);
ret = g_memdup2(user, sizeof *user);

if (deep) {
ret->name = g_strdup(user->name);
Expand Down
4 changes: 2 additions & 2 deletions pidgin/libpurple/protocols/facebook/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ fb_data_set_unread(FbData *fata, FbId id, gboolean unread)
return;
}

key = g_memdup(&id, sizeof id);
key = g_memdup2(&id, sizeof id);
g_hash_table_replace(priv->unread, key, GINT_TO_POINTER(unread));
}

Expand Down Expand Up @@ -523,7 +523,7 @@ fb_data_image_dup_image(FbDataImage *img, gsize *size)
return NULL;
}

return g_memdup(priv->image, priv->size);
return g_memdup2(priv->image, priv->size);
}

const gchar *
Expand Down
2 changes: 1 addition & 1 deletion pidgin/libpurple/protocols/facebook/facebook.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ fb_blist_chat_create(GSList *buddies, gpointer data)
for (l = buddies; l != NULL; l = l->next) {
name = purple_buddy_get_name(l->data);
uid = FB_ID_FROM_STR(name);
did = g_memdup(&uid, sizeof uid);
did = g_memdup2(&uid, sizeof uid);
uids = g_slist_prepend(uids, did);
}

Expand Down