Skip to content

Commit

Permalink
Merge Richard Cohen's 'remove-unneeded-memcpy' into stable.
Browse files Browse the repository at this point in the history
  • Loading branch information
jralls committed Jun 18, 2023
2 parents aae568e + 3abc9a5 commit 241aa1d
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 24 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,6 @@ if (UNIX OR MINGW)
set (HAVE_GETTIMEOFDAY 1)
set (HAVE_GUILE 1)
set (HAVE_LIBM 1)
set (HAVE_MEMCPY 1)
set (STDC_HEADERS 1)
set (_ALL_SOURCE 1)
set (_GNU_SOURCE 1)
Expand Down
3 changes: 0 additions & 3 deletions common/config.h.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@
/* Define to 1 if you have the <mcheck.h> header file. */
#cmakedefine HAVE_MCHECK_H 1

/* Define to 1 if you have the `memcpy' function. */
#cmakedefine HAVE_MEMCPY 1

/* Define to 1 if you have the <memory.h> header file. */
#cmakedefine HAVE_MEMORY_H 1

Expand Down
8 changes: 4 additions & 4 deletions gnucash/gnome-utils/gnc-autoclear.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ static void sack_foreach_func(gpointer key, gpointer value, gpointer user_data)
sack_foreach_data_t data = (sack_foreach_data_t) user_data;
gnc_numeric thisvalue = *(gnc_numeric *) key;
gnc_numeric reachable_value = gnc_numeric_add_fixed (thisvalue, data->split_value);
gpointer new_value = g_malloc(sizeof(gnc_numeric));
gnc_numeric* new_value = g_new(gnc_numeric, 1);

memcpy(new_value, &reachable_value, sizeof(gnc_numeric));
*new_value = reachable_value;
data->reachable_list = g_list_prepend(data->reachable_list, new_value);
}

Expand Down Expand Up @@ -108,7 +108,7 @@ gnc_account_get_autoclear_splits (Account *account, gnc_numeric toclear_value,
{
Split *split = (Split *)node->data;
gnc_numeric split_value = xaccSplitGetAmount (split);
gpointer new_value = g_malloc(sizeof(gnc_numeric));
gnc_numeric *new_value = g_new(gnc_numeric, 1);

struct _sack_foreach_data_t s_data[1];
s_data->split_value = split_value;
Expand All @@ -118,7 +118,7 @@ gnc_account_get_autoclear_splits (Account *account, gnc_numeric toclear_value,
g_hash_table_foreach (sack, sack_foreach_func, s_data);

/* Add the value of the split itself to the reachable_list */
memcpy(new_value, &split_value, sizeof(gnc_numeric));
*new_value = split_value;
s_data->reachable_list = g_list_prepend
(s_data->reachable_list, new_value);

Expand Down
8 changes: 3 additions & 5 deletions gnucash/register/register-gnome/gnucash-style.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ style_get_key (SheetBlockStyle *style)
static gpointer
style_create_key (SheetBlockStyle *style)
{
static gint key;
gpointer new_key;
gint key = style->cursor->num_rows;

key = style->cursor->num_rows;
new_key = g_malloc(sizeof(key));
new_key = memcpy(new_key, &key, sizeof(key));
gint *new_key = g_new(gint, 1);
*new_key = key;

return new_key;
}
Expand Down
2 changes: 1 addition & 1 deletion libgnucash/backend/sql/gnc-slots-sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ _retrieve_guid_ (gpointer pObject, gpointer pValue)
g_return_if_fail (pObject != NULL);
g_return_if_fail (pValue != NULL);

memcpy (pGuid, guid, sizeof (GncGUID));
*pGuid = *guid;
}

/* Special column table because we need to be able to access the table by
Expand Down
2 changes: 1 addition & 1 deletion libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ _retrieve_guid_ (gpointer pObject, gpointer pValue)
g_return_if_fail (pObject != NULL);
g_return_if_fail (pValue != NULL);

memcpy (pGuid, guid, sizeof (GncGUID));
*pGuid = *guid;
}

// Table to retrieve just the guid
Expand Down
4 changes: 2 additions & 2 deletions libgnucash/engine/SchedXaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,8 +1118,8 @@ gnc_sx_clone_temporal_state (SXTmpStateData *tsd)

if(tsd)
{
toRet = g_malloc(sizeof(SXTmpStateData));
toRet = memcpy (toRet, tsd, sizeof (SXTmpStateData));
toRet = g_new(SXTmpStateData, 1);
*toRet = *tsd;
}

return toRet;
Expand Down
3 changes: 1 addition & 2 deletions libgnucash/engine/gncOwner.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

#include <glib.h>
#include <glib/gi18n.h>
#include <string.h> /* for memcpy() */
#include <qofinstance-p.h>

#include "gncCustomerP.h"
Expand Down Expand Up @@ -399,7 +398,7 @@ void gncOwnerCopy (const GncOwner *src, GncOwner *dest)
{
if (!src || !dest) return;
if (src == dest) return;
memcpy (dest, src, sizeof (*dest));
*dest = *src;
}

gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b)
Expand Down
5 changes: 3 additions & 2 deletions libgnucash/engine/guid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <boost/uuid/uuid_io.hpp>
#include <sstream>
#include <string>
#include <algorithm>

/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = QOF_MOD_ENGINE;
Expand Down Expand Up @@ -120,7 +121,7 @@ guid_copy (const GncGUID *guid)
{
if (!guid) return nullptr;
auto ret = guid_malloc ();
memcpy (ret, guid, sizeof (GncGUID));
*ret = *guid;
return ret;
}

Expand All @@ -134,7 +135,7 @@ guid_null (void)
static void
guid_assign (GncGUID & target, gnc::GUID const & source)
{
memcpy (&target, &source, sizeof (GncGUID));
std::copy (source.begin(), source.end(), target.reserved);
}

/*Takes an allocated guid pointer and constructs it in place*/
Expand Down
6 changes: 3 additions & 3 deletions libgnucash/engine/qofquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static QofQueryTerm * copy_query_term (const QofQueryTerm *qt)
if (!qt) return NULL;

new_qt = g_new0 (QofQueryTerm, 1);
memcpy (new_qt, qt, sizeof(QofQueryTerm));
*new_qt = *qt;
new_qt->param_list = g_slist_copy (qt->param_list);
new_qt->param_fcns = g_slist_copy (qt->param_fcns);
new_qt->pdata = qof_query_core_predicate_copy (qt->pdata);
Expand Down Expand Up @@ -224,7 +224,7 @@ copy_or_terms(const GList * or_terms)

static void copy_sort (QofQuerySort *dst, const QofQuerySort *src)
{
memcpy (dst, src, sizeof (*dst));
*dst = *src;
dst->param_list = g_slist_copy (src->param_list);
dst->param_fcns = g_slist_copy (src->param_fcns);
}
Expand Down Expand Up @@ -1006,7 +1006,7 @@ QofQuery * qof_query_copy (QofQuery *q)
ht = copy->be_compiled;
free_members (copy);

memcpy (copy, q, sizeof (QofQuery));
*copy = *q;

copy->be_compiled = ht;
copy->terms = copy_or_terms (q->terms);
Expand Down

0 comments on commit 241aa1d

Please sign in to comment.