mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-11-21 08:34:15 -06:00
Refactor: Remove some unnecessary uses of memcpy
- Also, remove unnecessary "static" in gnucash-style.c The second one in guid.cpp is UB: libgnucash/engine/guid.cpp:137:5: warning: undefined behavior, source object type 'const gnc::GUID' is not TriviallyCopyable [bugprone-undefined-memory-manipulation] memcpy (&target, &source, sizeof (GncGUID)); ^
This commit is contained in:
parent
4a60e01fcd
commit
3abc9a5558
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -33,7 +33,6 @@
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <string.h> /* for memcpy() */
|
||||
#include <qofinstance-p.h>
|
||||
|
||||
#include "gncCustomerP.h"
|
||||
@ -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)
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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*/
|
||||
|
@ -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);
|
||||
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user