Corrected uses of guid_to_string.

Previously, guid_to_string had been marked deprecated with a note about
it not being thread-safe. It was much worse than "not thread safe", it
was only safe in a particular situation, and its safety was being violated
throughout the code. It was clear that users of guid_to_string did not
understand what it was purporting to do because of its varied uses. Most
uses simply treated it like a Garbage-Collected Java String (use and forget).
I actually found at least one instance where the string was being freed. (!!!)

I made the method have a particular easy-to-understand semantic: it returns
a pointer to a string which must be freed by the caller. I then tried to
track down all uses of this function and correct them. Mostly, I just changed
the usage to guid_to_string_buff with a stack-allocated string to avoid the
the malloc/free cycle.
This commit is contained in:
lmat 2014-07-25 17:02:44 -04:00
parent 2a408ab9ef
commit 30fac05e35
33 changed files with 187 additions and 155 deletions

View File

@ -260,8 +260,10 @@ gnc_cm_event_handler (QofInstance *entity,
{ {
const GncGUID *guid = qof_entity_get_guid(entity); const GncGUID *guid = qof_entity_get_guid(entity);
#if CM_DEBUG #if CM_DEBUG
gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff (guid, guidstr);
fprintf (stderr, "event_handler: event %d, entity %p, guid %s\n", event_type, fprintf (stderr, "event_handler: event %d, entity %p, guid %s\n", event_type,
entity, guid_to_string(guid)); entity, guidstr);
#endif #endif
add_event (&changes, guid, event_type, TRUE); add_event (&changes, guid, event_type, TRUE);

View File

@ -71,7 +71,8 @@ gnc_state_set_base (const QofSession *session)
{ {
gchar *basename, *original = NULL, *filename, *file_guid; gchar *basename, *original = NULL, *filename, *file_guid;
gchar *sf_extension = NULL, *newstyle_filename = NULL; gchar *sf_extension = NULL, *newstyle_filename = NULL;
const gchar *uri, *guid_string; const gchar *uri;
gchar guid_string[GUID_ENCODING_LENGTH+1];
QofBook *book; QofBook *book;
const GncGUID *guid; const GncGUID *guid;
GKeyFile *key_file = NULL; GKeyFile *key_file = NULL;
@ -94,7 +95,7 @@ gnc_state_set_base (const QofSession *session)
/* Get the book GncGUID */ /* Get the book GncGUID */
book = qof_session_get_book(session); book = qof_session_get_book(session);
guid = qof_entity_get_guid(QOF_INSTANCE(book)); guid = qof_entity_get_guid(QOF_INSTANCE(book));
guid_string = guid_to_string(guid); guid_to_string_buff(guid, guid_string);
if (gnc_uri_is_file_uri (uri)) if (gnc_uri_is_file_uri (uri))
{ {

View File

@ -1490,6 +1490,8 @@ static void add_to_hash_amount(GHashTable* hash, const GncGUID* guid, const gnc_
* modify it in-place; if not, insert the new element into the * modify it in-place; if not, insert the new element into the
* hash. */ * hash. */
gnc_numeric* elem = g_hash_table_lookup(hash, guid); gnc_numeric* elem = g_hash_table_lookup(hash, guid);
gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff(guid, guidstr);
if (!elem) if (!elem)
{ {
elem = g_new0(gnc_numeric, 1); elem = g_new0(gnc_numeric, 1);
@ -1503,7 +1505,7 @@ static void add_to_hash_amount(GHashTable* hash, const GncGUID* guid, const gnc_
g_critical("Oops, the given amount [%s] has the error code %d, at guid [%s].", g_critical("Oops, the given amount [%s] has the error code %d, at guid [%s].",
gnc_num_dbg_to_string(*amount), gnc_num_dbg_to_string(*amount),
gnc_numeric_check(*amount), gnc_numeric_check(*amount),
guid_to_string(guid)); guidstr);
return; return;
} }
if (gnc_numeric_check(*elem) != GNC_ERROR_OK) if (gnc_numeric_check(*elem) != GNC_ERROR_OK)
@ -1511,7 +1513,7 @@ static void add_to_hash_amount(GHashTable* hash, const GncGUID* guid, const gnc_
g_critical("Oops, the account's amount [%s] has the error code %d, at guid [%s].", g_critical("Oops, the account's amount [%s] has the error code %d, at guid [%s].",
gnc_num_dbg_to_string(*elem), gnc_num_dbg_to_string(*elem),
gnc_numeric_check(*elem), gnc_numeric_check(*elem),
guid_to_string(guid)); guidstr);
return; return;
} }
@ -1527,7 +1529,7 @@ static void add_to_hash_amount(GHashTable* hash, const GncGUID* guid, const gnc_
if (gnc_numeric_check(*elem) != GNC_ERROR_OK) if (gnc_numeric_check(*elem) != GNC_ERROR_OK)
{ {
g_critical("Oops, after addition at guid [%s] the resulting amount [%s] has the error code %d; added amount = [%s].", g_critical("Oops, after addition at guid [%s] the resulting amount [%s] has the error code %d; added amount = [%s].",
guid_to_string(guid), guidstr,
gnc_num_dbg_to_string(*elem), gnc_num_dbg_to_string(*elem),
gnc_numeric_check(*elem), gnc_numeric_check(*elem),
gnc_num_dbg_to_string(*amount)); gnc_num_dbg_to_string(*amount));
@ -1536,7 +1538,7 @@ static void add_to_hash_amount(GHashTable* hash, const GncGUID* guid, const gnc_
/* In case anyone wants to see this in the debug log. */ /* In case anyone wants to see this in the debug log. */
g_debug("Adding to guid [%s] the value [%s]. Value now [%s].", g_debug("Adding to guid [%s] the value [%s]. Value now [%s].",
guid_to_string(guid), guidstr,
gnc_num_dbg_to_string(*amount), gnc_num_dbg_to_string(*amount),
gnc_num_dbg_to_string(*elem)); gnc_num_dbg_to_string(*elem));
} }

View File

@ -297,7 +297,7 @@ gnc_is_trans_scm(SCM scm)
void void
gnc_split_scm_set_account(SCM split_scm, Account *account) gnc_split_scm_set_account(SCM split_scm, Account *account)
{ {
const char *guid_string; gchar guid_string[GUID_ENCODING_LENGTH+1];
SCM arg; SCM arg;
initialize_scm_functions(); initialize_scm_functions();
@ -307,7 +307,7 @@ gnc_split_scm_set_account(SCM split_scm, Account *account)
if (account == NULL) if (account == NULL)
return; return;
guid_string = guid_to_string(xaccAccountGetGUID(account)); guid_to_string_buff(xaccAccountGetGUID(account), guid_string);
if (guid_string == NULL) if (guid_string == NULL)
return; return;
@ -657,6 +657,7 @@ gnc_copy_trans_scm_onto_trans_swap_accounts(SCM trans_scm,
} }
else else
{ {
gchar guidstr[GUID_ENCODING_LENGTH+1];
SCM from, to; SCM from, to;
SCM map = SCM_EOL; SCM map = SCM_EOL;
SCM args = SCM_EOL; SCM args = SCM_EOL;
@ -668,8 +669,10 @@ gnc_copy_trans_scm_onto_trans_swap_accounts(SCM trans_scm,
args = scm_cons(commit, args); args = scm_cons(commit, args);
from = scm_from_utf8_string(guid_to_string(guid_1)); guid_to_string_buff(guid_1, guidstr);
to = scm_from_utf8_string(guid_to_string(guid_2)); from = scm_from_utf8_string(guidstr);
guid_to_string_buff(guid_2, guidstr);
to = scm_from_utf8_string(guidstr);
map = scm_cons(scm_cons(from, to), map); map = scm_cons(scm_cons(from, to), map);
map = scm_cons(scm_cons(to, from), map); map = scm_cons(scm_cons(to, from), map);

View File

@ -225,10 +225,11 @@ load_single_split( GncSqlBackend* be, GncSqlRow* row )
/*# -ifempty */ /*# -ifempty */
if (pSplit != xaccSplitLookup( &split_guid, be->book )) if (pSplit != xaccSplitLookup( &split_guid, be->book ))
{ {
PERR("A malformed split with id %s was found in the dataset.", gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string(qof_instance_get_guid(pSplit))); guid_to_string_buff(qof_instance_get_guid(pSplit), guidstr);
qof_backend_set_error( &be->be, ERR_BACKEND_DATA_CORRUPT); PERR("A malformed split with id %s was found in the dataset.", guidstr);
pSplit = NULL; qof_backend_set_error( &be->be, ERR_BACKEND_DATA_CORRUPT);
pSplit = NULL;
} }
return pSplit; return pSplit;
} }
@ -305,10 +306,11 @@ load_single_tx( GncSqlBackend* be, GncSqlRow* row )
if (pTx != xaccTransLookup( &tx_guid, be->book )) if (pTx != xaccTransLookup( &tx_guid, be->book ))
{ {
PERR("A malformed transaction with id %s was found in the dataset.", gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string(qof_instance_get_guid(pTx))); guid_to_string_buff(qof_instance_get_guid(pTx), guidstr);
qof_backend_set_error( &be->be, ERR_BACKEND_DATA_CORRUPT); PERR("A malformed transaction with id %s was found in the dataset.", guidstr);
pTx = NULL; qof_backend_set_error( &be->be, ERR_BACKEND_DATA_CORRUPT);
pTx = NULL;
} }
return pTx; return pTx;

View File

@ -588,8 +588,9 @@ billterm_scrub_cb (QofInstance *term_p, gpointer list_p)
if (t) if (t)
{ {
/* Fix up the broken "copy" function */ /* Fix up the broken "copy" function */
PWARN("Fixing broken child billterm: %s", gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term)))); guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(term)),guidstr);
PWARN("Fixing broken child billterm: %s", guidstr);
gncBillTermBeginEdit(term); gncBillTermBeginEdit(term);
gncBillTermSetType(term, gncBillTermGetType(t)); gncBillTermSetType(term, gncBillTermGetType(t));
@ -624,8 +625,9 @@ billterm_scrub_invoices (QofInstance * invoice_p, gpointer ht_p)
{ {
if (billterm_is_grandchild(term)) if (billterm_is_grandchild(term))
{ {
PWARN("Fixing i-billterm on invoice %s\n", gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(invoice)))); guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(invoice)),guidstr);
PWARN("Fixing i-billterm on invoice %s\n", guidstr);
new_bt = billterm_find_senior(term); new_bt = billterm_find_senior(term);
gncInvoiceBeginEdit(invoice); gncInvoiceBeginEdit(invoice);
gncInvoiceSetTerms(invoice, new_bt); gncInvoiceSetTerms(invoice, new_bt);
@ -656,9 +658,13 @@ billterm_scrub_cust (QofInstance * cust_p, gpointer ht_p)
count++; count++;
g_hash_table_insert(ht, term, GINT_TO_POINTER(count)); g_hash_table_insert(ht, term, GINT_TO_POINTER(count));
if (billterm_is_grandchild(term)) if (billterm_is_grandchild(term))
PWARN("customer %s has grandchild billterm %s\n", {
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(cust))), gchar custstr[GUID_ENCODING_LENGTH+1];
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term)))); gchar termstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(cust)),custstr);
guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(term)),termstr);
PWARN("customer %s has grandchild billterm %s\n", custstr,termstr);
}
} }
} }
@ -677,9 +683,13 @@ billterm_scrub_vendor (QofInstance * vendor_p, gpointer ht_p)
count++; count++;
g_hash_table_insert(ht, term, GINT_TO_POINTER(count)); g_hash_table_insert(ht, term, GINT_TO_POINTER(count));
if (billterm_is_grandchild(term)) if (billterm_is_grandchild(term))
PWARN("vendor %s has grandchild billterm %s\n", {
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(vendor))), gchar vendstr[GUID_ENCODING_LENGTH+1];
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term)))); gchar termstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(vendor)),vendstr);
guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(term)),termstr);
PWARN("vendor %s has grandchild billterm %s\n", vendstr, termstr);
}
} }
} }
@ -691,9 +701,10 @@ billterm_reset_refcount (gpointer key, gpointer value, gpointer notused)
if (count != gncBillTermGetRefcount(term) && !gncBillTermGetInvisible(term)) if (count != gncBillTermGetRefcount(term) && !gncBillTermGetInvisible(term))
{ {
gchar termstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(term)),termstr);
PWARN("Fixing refcount on billterm %s (%" G_GINT64_FORMAT " -> %d)\n", PWARN("Fixing refcount on billterm %s (%" G_GINT64_FORMAT " -> %d)\n",
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))), termstr, gncBillTermGetRefcount(term), count);
gncBillTermGetRefcount(term), count);
gncBillTermSetRefcount(term, count); gncBillTermSetRefcount(term, count);
} }
} }
@ -715,10 +726,11 @@ billterm_scrub (QofBook *book)
/* destroy the list of "grandchildren" bill terms */ /* destroy the list of "grandchildren" bill terms */
for (node = list; node; node = node->next) for (node = list; node; node = node->next)
{ {
gchar termstr[GUID_ENCODING_LENGTH+1];
term = node->data; term = node->data;
PWARN ("deleting grandchild billterm: %s\n", guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(term)), termstr);
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term)))); PWARN ("deleting grandchild billterm: %s\n", termstr);
/* Make sure the parent has no children */ /* Make sure the parent has no children */
parent = gncBillTermGetParent(term); parent = gncBillTermGetParent(term);
@ -770,11 +782,13 @@ GncBillTerm *
gnc_billterm_xml_find_or_create(QofBook *book, GncGUID *guid) gnc_billterm_xml_find_or_create(QofBook *book, GncGUID *guid)
{ {
GncBillTerm *term; GncBillTerm *term;
gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff(guid, guidstr);
g_return_val_if_fail(book, NULL); g_return_val_if_fail(book, NULL);
g_return_val_if_fail(guid, NULL); g_return_val_if_fail(guid, NULL);
term = gncBillTermLookup(book, guid); term = gncBillTermLookup(book, guid);
DEBUG("looking for billterm %s, found %p", guid_to_string(guid), term); DEBUG("looking for billterm %s, found %p", guidstr, term);
if (!term) if (!term)
{ {
term = gncBillTermCreate(book); term = gncBillTermCreate(book);

View File

@ -740,10 +740,10 @@ gnc_schedXaction_end_handler(gpointer data_for_children,
if ( sx->template_acct == NULL ) if ( sx->template_acct == NULL )
{ {
Account *ra = NULL; Account *ra = NULL;
const char *id = NULL;
Account *acct = NULL; Account *acct = NULL;
sixtp_gdv2 *sixdata = gdata->parsedata; sixtp_gdv2 *sixdata = gdata->parsedata;
QofBook *book; QofBook *book;
gchar guidstr[GUID_ENCODING_LENGTH+1];
book = sixdata->book; book = sixdata->book;
@ -751,8 +751,7 @@ gnc_schedXaction_end_handler(gpointer data_for_children,
change re: storing template accounts. */ change re: storing template accounts. */
/* Fix: get account with name of our GncGUID from the template /* Fix: get account with name of our GncGUID from the template
accounts. Make that our template_acct pointer. */ accounts. Make that our template_acct pointer. */
/* THREAD-UNSAFE */ guid_to_string_buff( xaccSchedXactionGetGUID( sx ), guidstr );
id = guid_to_string( xaccSchedXactionGetGUID( sx ) );
ra = gnc_book_get_template_root(book); ra = gnc_book_get_template_root(book);
if ( ra == NULL ) if ( ra == NULL )
{ {
@ -760,15 +759,15 @@ gnc_schedXaction_end_handler(gpointer data_for_children,
xmlFreeNode( tree ); xmlFreeNode( tree );
return FALSE; return FALSE;
} }
acct = gnc_account_lookup_by_name( ra, id ); acct = gnc_account_lookup_by_name( ra, guidstr );
if ( acct == NULL ) if ( acct == NULL )
{ {
g_warning("no template account with name [%s]", id); g_warning("no template account with name [%s]", guidstr);
xmlFreeNode( tree ); xmlFreeNode( tree );
return FALSE; return FALSE;
} }
g_debug("template account name [%s] for SX with GncGUID [%s]", g_debug("template account name [%s] for SX with GncGUID [%s]",
xaccAccountGetName( acct ), id ); xaccAccountGetName( acct ), guidstr );
/* FIXME: free existing template account. /* FIXME: free existing template account.
* HUH????? We only execute this if there isn't * HUH????? We only execute this if there isn't

View File

@ -576,8 +576,9 @@ taxtable_scrub_entries (QofInstance * entry_p, gpointer ht_p)
{ {
if (taxtable_is_grandchild(table)) if (taxtable_is_grandchild(table))
{ {
PINFO("Fixing i-taxtable on entry %s\n", gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(entry)))); guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(entry)),guidstr);
PINFO("Fixing i-taxtable on entry %s\n",guidstr);
new_tt = taxtable_find_senior(table); new_tt = taxtable_find_senior(table);
gncEntryBeginEdit(entry); gncEntryBeginEdit(entry);
gncEntrySetInvTaxTable(entry, new_tt); gncEntrySetInvTaxTable(entry, new_tt);
@ -597,8 +598,9 @@ taxtable_scrub_entries (QofInstance * entry_p, gpointer ht_p)
{ {
if (taxtable_is_grandchild(table)) if (taxtable_is_grandchild(table))
{ {
PINFO("Fixing b-taxtable on entry %s\n", gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(entry)))); guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(entry)),guidstr);
PINFO("Fixing b-taxtable on entry %s\n",guidstr);
new_tt = taxtable_find_senior(table); new_tt = taxtable_find_senior(table);
gncEntryBeginEdit(entry); gncEntryBeginEdit(entry);
gncEntrySetBillTaxTable(entry, new_tt); gncEntrySetBillTaxTable(entry, new_tt);
@ -656,9 +658,10 @@ taxtable_reset_refcount (gpointer key, gpointer value, gpointer notused)
if (count != gncTaxTableGetRefcount(table) && !gncTaxTableGetInvisible(table)) if (count != gncTaxTableGetRefcount(table) && !gncTaxTableGetInvisible(table))
{ {
gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(table)),guidstr);
PWARN("Fixing refcount on taxtable %s (%" G_GINT64_FORMAT " -> %d)\n", PWARN("Fixing refcount on taxtable %s (%" G_GINT64_FORMAT " -> %d)\n",
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(table))), guidstr,gncTaxTableGetRefcount(table), count);
gncTaxTableGetRefcount(table), count);
gncTaxTableSetRefcount(table, count); gncTaxTableSetRefcount(table, count);
} }
} }
@ -679,10 +682,11 @@ taxtable_scrub (QofBook *book)
/* destroy the list of "grandchildren" tax tables */ /* destroy the list of "grandchildren" tax tables */
for (node = list; node; node = node->next) for (node = list; node; node = node->next)
{ {
gchar guidstr[GUID_ENCODING_LENGTH+1];
table = node->data; table = node->data;
PINFO ("deleting grandchild taxtable: %s\n", guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(table)),guidstr);
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(table)))); PINFO ("deleting grandchild taxtable: %s\n", guidstr);
/* Make sure the parent has no children */ /* Make sure the parent has no children */
parent = gncTaxTableGetParent(table); parent = gncTaxTableGetParent(table);

View File

@ -308,10 +308,12 @@ add_kvp_value_node(xmlNodePtr node, gchar *tag, kvp_value* val)
xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "string"); xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "string");
break; break;
case KVP_TYPE_GUID: case KVP_TYPE_GUID:
/* THREAD-UNSAFE */ {
add_text_to_node(val_node, "guid", gchar guidstr[GUID_ENCODING_LENGTH+1];
g_strdup(guid_to_string(kvp_value_get_guid(val)))); guid_to_string_buff(kvp_value_get_guid(val), guidstr);
add_text_to_node(val_node, "guid", guidstr);
break; break;
}
case KVP_TYPE_TIMESPEC: case KVP_TYPE_TIMESPEC:
{ {
Timespec ts = kvp_value_get_timespec (val); Timespec ts = kvp_value_get_timespec (val);

View File

@ -218,7 +218,9 @@ equals_node_val_vs_splits(xmlNodePtr node, const Transaction *trn)
if (!spl_node) if (!spl_node)
{ {
g_print( "Split GUID %s", guid_to_string(xaccSplitGetGUID(spl_mark)) ); gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff(xaccSplitGetGUID(spl_mark),guidstr);
g_print( "Split GUID %s", guidstr );
return "no matching split found"; return "no matching split found";
} }

View File

@ -2177,24 +2177,25 @@ gnc_invoice_save_page (InvoiceWindow *iw,
GKeyFile *key_file, GKeyFile *key_file,
const gchar *group_name) const gchar *group_name)
{ {
gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff(&iw->invoice_guid, guidstr);
g_key_file_set_string(key_file, group_name, KEY_INVOICE_TYPE, g_key_file_set_string(key_file, group_name, KEY_INVOICE_TYPE,
InvoiceDialogTypeasString(iw->dialog_type)); InvoiceDialogTypeasString(iw->dialog_type));
g_key_file_set_string(key_file, group_name, KEY_INVOICE_GUID, g_key_file_set_string(key_file, group_name, KEY_INVOICE_GUID, guidstr);
guid_to_string(&iw->invoice_guid));
if (gncOwnerGetJob (&(iw->job))) if (gncOwnerGetJob (&(iw->job)))
{ {
g_key_file_set_string(key_file, group_name, KEY_OWNER_TYPE, g_key_file_set_string(key_file, group_name, KEY_OWNER_TYPE,
qofOwnerGetType(&iw->job)); qofOwnerGetType(&iw->job));
g_key_file_set_string(key_file, group_name, KEY_OWNER_GUID, guid_to_string_buff(gncOwnerGetGUID(&iw->job), guidstr);
guid_to_string(gncOwnerGetGUID(&iw->job))); g_key_file_set_string(key_file, group_name, KEY_OWNER_GUID, guidstr);
} }
else else
{ {
g_key_file_set_string(key_file, group_name, KEY_OWNER_TYPE, g_key_file_set_string(key_file, group_name, KEY_OWNER_TYPE,
qofOwnerGetType(&iw->owner)); qofOwnerGetType(&iw->owner));
g_key_file_set_string(key_file, group_name, KEY_OWNER_GUID, guid_to_string_buff(gncOwnerGetGUID(&iw->owner), guidstr);
guid_to_string(gncOwnerGetGUID(&iw->owner))); g_key_file_set_string(key_file, group_name, KEY_OWNER_GUID, guidstr);
} }
} }

View File

@ -287,12 +287,12 @@ Return the @code{memcmp} of the two GUID's.
You can encode and decode GUIDs and their string representations using the You can encode and decode GUIDs and their string representations using the
next two functions. next two functions.
@deftypefun {const char *} guid_to_string (const GUID * @var{guid}) @deftypefun {gchar *} guid_to_string (const GUID * @var{guid})
Return a null-terminated string encoding of @var{guid}. String encodings Return a null-terminated string encoding of @var{guid}. String encodings
of identifiers are hex numbers printed only with the characters @code{0} of identifiers are hex numbers printed only with the characters @code{0}
through @code{9} and @code{a} through @code{f}. The encoding will through @code{9} and @code{a} through @code{f}. The encoding will
always be @code{GUID_ENCODING_LENGTH} characters long. The returned always be @code{GUID_ENCODING_LENGTH} characters long. The returned
string must NOT be freed when no longer needed. string must be freed when no longer needed using g_free.
@end deftypefun @end deftypefun
@deftypefun {char *} guid_to_string_buff (const GUID * @var{guid}, char * @var{buff}) @deftypefun {char *} guid_to_string_buff (const GUID * @var{guid}, char * @var{buff})

View File

@ -380,6 +380,7 @@ xaccSchedXactionInit(SchedXaction *sx, QofBook *book)
{ {
Account *ra; Account *ra;
const GncGUID *guid; const GncGUID *guid;
gchar guidstr[GUID_ENCODING_LENGTH+1];
qof_instance_init_data (&sx->inst, GNC_ID_SCHEDXACTION, book); qof_instance_init_data (&sx->inst, GNC_ID_SCHEDXACTION, book);
@ -387,7 +388,8 @@ xaccSchedXactionInit(SchedXaction *sx, QofBook *book)
sx->template_acct = xaccMallocAccount(book); sx->template_acct = xaccMallocAccount(book);
guid = qof_instance_get_guid( sx ); guid = qof_instance_get_guid( sx );
xaccAccountBeginEdit( sx->template_acct ); xaccAccountBeginEdit( sx->template_acct );
xaccAccountSetName( sx->template_acct, guid_to_string( guid )); guid_to_string_buff( guid, guidstr );
xaccAccountSetName( sx->template_acct, guidstr);
xaccAccountSetCommodity xaccAccountSetCommodity
(sx->template_acct, (sx->template_acct,
gnc_commodity_table_lookup( gnc_commodity_table_get_table(book), gnc_commodity_table_lookup( gnc_commodity_table_get_table(book),

View File

@ -1450,8 +1450,10 @@ xaccSplitConvertAmount (const Split *split, const Account * account)
xaccAccountGetCommodity(xaccSplitGetAccount(osplit)); xaccAccountGetCommodity(xaccSplitGetAccount(osplit));
if (!gnc_commodity_equal(to_commodity, split_comm)) if (!gnc_commodity_equal(to_commodity, split_comm))
{ {
gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff(xaccSplitGetGUID(osplit),guidstr);
PERR("The split's (%s) amount can't be converted from %s into %s.", PERR("The split's (%s) amount can't be converted from %s into %s.",
guid_to_string(xaccSplitGetGUID(osplit)), guidstr,
gnc_commodity_get_mnemonic(split_comm), gnc_commodity_get_mnemonic(split_comm),
gnc_commodity_get_mnemonic(to_commodity) gnc_commodity_get_mnemonic(to_commodity)
); );

View File

@ -971,8 +971,10 @@ xaccTransEqual(const Transaction *ta, const Transaction *tb,
if (!node_b) if (!node_b)
{ {
PINFO ("first has split %s and second does not", gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string (xaccSplitGetGUID (split_a))); guid_to_string_buff (xaccSplitGetGUID (split_a),guidstr);
PINFO ("first has split %s and second does not",guidstr);
return FALSE; return FALSE;
} }

View File

@ -266,9 +266,10 @@ GncBillTerm * gncBillTermCreate (QofBook *book)
void gncBillTermDestroy (GncBillTerm *term) void gncBillTermDestroy (GncBillTerm *term)
{ {
gchar guidstr[GUID_ENCODING_LENGTH+1];
if (!term) return; if (!term) return;
DEBUG("destroying bill term %s (%p)", guid_to_string_buff(qof_instance_get_guid(&term->inst),guidstr);
guid_to_string(qof_instance_get_guid(&term->inst)), term); DEBUG("destroying bill term %s (%p)", guidstr, term);
qof_instance_set_destroying(term, TRUE); qof_instance_set_destroying(term, TRUE);
qof_instance_set_dirty (&term->inst); qof_instance_set_dirty (&term->inst);
gncBillTermCommitEdit (term); gncBillTermCommitEdit (term);

View File

@ -974,6 +974,7 @@ test_xaccSplitConvertAmount (void)
"GNCXX", "", 1000); "GNCXX", "", 1000);
gnc_commodity *gnm = gnc_commodity_new (book, "Gnome, Inc.", "NYSE", gnc_commodity *gnm = gnc_commodity_new (book, "Gnome, Inc.", "NYSE",
"GNM", "", 1000); "GNM", "", 1000);
gchar guidstr[GUID_ENCODING_LENGTH+1];
Account *acc = xaccMallocAccount (book); Account *acc = xaccMallocAccount (book);
Account *o_acc = xaccMallocAccount (book); Account *o_acc = xaccMallocAccount (book);
@ -991,7 +992,8 @@ test_xaccSplitConvertAmount (void)
TestErrorStruct check = { loglevel, logdomain, NULL, 0 }; TestErrorStruct check = { loglevel, logdomain, NULL, 0 };
GLogFunc oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, &check); GLogFunc oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, &check);
check.msg = g_strdup_printf ("[xaccSplitConvertAmount()] The split's (%s) amount can't be converted from GNCXX into GNM.", guid_to_string(xaccSplitGetGUID(o_split))); guid_to_string_buff(xaccSplitGetGUID(o_split), guidstr);
check.msg = g_strdup_printf ("[xaccSplitConvertAmount()] The split's (%s) amount can't be converted from GNCXX into GNM.", guidstr);
xaccAccountSetCommodity (acc, gnaira); xaccAccountSetCommodity (acc, gnaira);
xaccAccountSetCommodity (o_acc, gnaira); xaccAccountSetCommodity (o_acc, gnaira);
xaccAccountSetCommodity (ya_acc, gnm); xaccAccountSetCommodity (ya_acc, gnm);

View File

@ -105,7 +105,7 @@ GList * logged_in_users = NULL;
*/ */
static const char * static const char *
auth_user (const char * name, const char *passwd) auth_user (const char * name, const char *passwd, char *buff)
{ {
GncGUID *guid; GncGUID *guid;
const char *session_auth_string; const char *session_auth_string;
@ -115,11 +115,11 @@ auth_user (const char * name, const char *passwd)
*/ */
if (!name || !passwd) return NULL; if (!name || !passwd) return NULL;
guid = g_new (GncGUID, 1); guid = guid_new();
guid_replace (guid);
logged_in_users = g_list_prepend (logged_in_users, guid); logged_in_users = g_list_prepend (logged_in_users, guid);
session_auth_string = guid_to_string (guid); /* THREAD UNSAFE */
return session_auth_string; guid_to_string_buffer (guid, buff);
return buff;
} }
/* /*
@ -244,6 +244,7 @@ main (int argc, char *argv[])
const char *user_agent; const char *user_agent;
const char *auth_string; const char *auth_string;
const char *content_length; const char *content_length;
gchar guidstr[GUID_ENCODING_LENGTH+1];
int read_len = 0; int read_len = 0;
int send_accts = 0; int send_accts = 0;
@ -301,7 +302,7 @@ main (int argc, char *argv[])
char *name = NULL, *passwd = NULL; char *name = NULL, *passwd = NULL;
parse_for_login (request_bufp, &name, &passwd); parse_for_login (request_bufp, &name, &passwd);
auth_string = auth_user (name, passwd); auth_string = auth_user (name, passwd, guidstr);
if (!auth_string) if (!auth_string)
{ {
reject_auth(); reject_auth();

View File

@ -1285,9 +1285,7 @@ schedXact_editor_create_ledger( GncSxEditorDialog *sxed )
GtkWidget *main_vbox; GtkWidget *main_vbox;
/* Create the ledger */ /* Create the ledger */
/* THREAD-UNSAFE */ sxed->sxGUIDstr = guid_to_string( xaccSchedXactionGetGUID(sxed->sx) );
sxed->sxGUIDstr = g_strdup( guid_to_string(
xaccSchedXactionGetGUID(sxed->sx) ) );
sxed->ledger = gnc_ledger_display_template_gl( sxed->sxGUIDstr ); sxed->ledger = gnc_ledger_display_template_gl( sxed->sxGUIDstr );
splitreg = gnc_ledger_display_get_split_register( sxed->ledger ); splitreg = gnc_ledger_display_get_split_register( sxed->ledger );

View File

@ -1276,8 +1276,7 @@ schedXact_editor_create_ledger (GncSxEditorDialog2 *sxed)
GtkWidget *label; GtkWidget *label;
/* Create the ledger */ /* Create the ledger */
/* THREAD-UNSAFE */ sxed->sxGUIDstr = guid_to_string (xaccSchedXactionGetGUID (sxed->sx));
sxed->sxGUIDstr = g_strdup (guid_to_string (xaccSchedXactionGetGUID (sxed->sx)));
sxed->ledger = gnc_ledger_display2_template_gl (sxed->sxGUIDstr); sxed->ledger = gnc_ledger_display2_template_gl (sxed->sxGUIDstr);
model = gnc_ledger_display2_get_split_model_register (sxed->ledger); model = gnc_ledger_display2_get_split_model_register (sxed->ledger);

View File

@ -289,6 +289,7 @@ gbv_create_widget(GncBudgetView *view)
GtkTreeIter iter; GtkTreeIter iter;
GtkWidget* h_separator; GtkWidget* h_separator;
gchar *state_section; gchar *state_section;
gchar guidstr[GUID_ENCODING_LENGTH+1];
priv = GNC_BUDGET_VIEW_GET_PRIVATE(view); priv = GNC_BUDGET_VIEW_GET_PRIVATE(view);
vbox = GTK_VBOX(view); vbox = GTK_VBOX(view);
@ -315,7 +316,8 @@ gbv_create_widget(GncBudgetView *view)
tree_view = gnc_tree_view_account_new(FALSE); tree_view = gnc_tree_view_account_new(FALSE);
gtk_container_add(GTK_CONTAINER(inner_scrolled_window), GTK_WIDGET(tree_view)); gtk_container_add(GTK_CONTAINER(inner_scrolled_window), GTK_WIDGET(tree_view));
state_section = g_strjoin(" ", STATE_SECTION_PREFIX, guid_to_string(&priv->key), NULL); guid_to_string_buff(&priv->key, guidstr);
state_section = g_strjoin(" ", STATE_SECTION_PREFIX, guidstr, NULL);
g_object_set(G_OBJECT(tree_view), "state-section", state_section, NULL); g_object_set(G_OBJECT(tree_view), "state-section", state_section, NULL);
g_free (state_section); g_free (state_section);
@ -487,13 +489,16 @@ void
gnc_budget_view_delete_budget(GncBudgetView *view) gnc_budget_view_delete_budget(GncBudgetView *view)
{ {
GncBudgetViewPrivate *priv; GncBudgetViewPrivate *priv;
gchar guidstr[GUID_ENCODING_LENGTH+1];
g_return_if_fail(view != NULL); g_return_if_fail(view != NULL);
ENTER("view %p", view); ENTER("view %p", view);
priv = GNC_BUDGET_VIEW_GET_PRIVATE (view); priv = GNC_BUDGET_VIEW_GET_PRIVATE (view);
gnc_state_drop_sections_for (guid_to_string (&priv->key));
guid_to_string_buff(&priv->key, guidstr);
gnc_state_drop_sections_for (guidstr);
g_object_set (G_OBJECT (priv->tree_view), "state-section", NULL, NULL); g_object_set (G_OBJECT (priv->tree_view), "state-section", NULL, NULL);
LEAVE(" "); LEAVE(" ");

View File

@ -1397,7 +1397,7 @@ gnc_plugin_page_account_tree_cmd_delete_account (GtkAction *action, GncPluginPag
{ {
GList *acct_list, *ptr; GList *acct_list, *ptr;
const GncGUID *guid; const GncGUID *guid;
const gchar *guid_str; gchar guidstr[GUID_ENCODING_LENGTH+1];
gnc_set_busy_cursor(NULL, TRUE); gnc_set_busy_cursor(NULL, TRUE);
gnc_suspend_gui_refresh (); gnc_suspend_gui_refresh ();
@ -1435,16 +1435,16 @@ gnc_plugin_page_account_tree_cmd_delete_account (GtkAction *action, GncPluginPag
for (ptr = acct_list; ptr; ptr = g_list_next(ptr)) for (ptr = acct_list; ptr; ptr = g_list_next(ptr))
{ {
guid = xaccAccountGetGUID (ptr->data); guid = xaccAccountGetGUID (ptr->data);
guid_str = guid_to_string (guid); guid_to_string_buff (guid, guidstr);
gnc_state_drop_sections_for (guid_str); gnc_state_drop_sections_for (guidstr);
} }
g_list_free(acct_list); g_list_free(acct_list);
/* Drop all references from the state file for this account /* Drop all references from the state file for this account
*/ */
guid = xaccAccountGetGUID (account); guid = xaccAccountGetGUID (account);
guid_str = guid_to_string (guid); guid_to_string_buff (guid, guidstr);
gnc_state_drop_sections_for (guid_str); gnc_state_drop_sections_for (guidstr);
/* /*
* Finally, delete the account, any subaccounts it may still * Finally, delete the account, any subaccounts it may still

View File

@ -385,16 +385,15 @@ static
void void
gsr_create_table( GNCSplitReg *gsr ) gsr_create_table( GNCSplitReg *gsr )
{ {
GtkWidget *register_widget; GtkWidget *register_widget = NULL;
SplitRegister *sr; SplitRegister *sr = NULL;
gchar *state_section; Account * account = gnc_ledger_display_leader(gsr->ledger);
const GncGUID * guid; const GncGUID * guid = xaccAccountGetGUID(account);
Account * account; gchar guidstr[GUID_ENCODING_LENGTH+1];
gchar *state_section = NULL;
account = gnc_ledger_display_leader(gsr->ledger); guid_to_string_buff(guid, guidstr);
guid = xaccAccountGetGUID(account); state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", guidstr, NULL);
state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", (gchar*)guid_to_string (guid), NULL);
ENTER("gsr=%p", gsr); ENTER("gsr=%p", gsr);
@ -693,13 +692,14 @@ gnc_split_reg_ld_destroy( GNCLedgerDisplay *ledger )
{ {
GNCSplitReg *gsr = gnc_ledger_display_get_user_data( ledger ); GNCSplitReg *gsr = gnc_ledger_display_get_user_data( ledger );
Account * account = gnc_ledger_display_leader(ledger);
const GncGUID * guid = xaccAccountGetGUID(account);
gchar guidstr[GUID_ENCODING_LENGTH+1];
gchar *state_section; gchar *state_section;
const GncGUID * guid;
Account * account;
account = gnc_ledger_display_leader(ledger); guid_to_string_buff(guid, guidstr);
guid = xaccAccountGetGUID(account);
state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ",(gchar*)guid_to_string (guid), NULL); state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", guidstr, NULL);
if (gsr) if (gsr)
{ {

View File

@ -262,9 +262,17 @@ gsr2_create_table (GNCSplitReg2 *gsr)
if (ledger_type == LD2_GL && model->type == GENERAL_LEDGER2) if (ledger_type == LD2_GL && model->type == GENERAL_LEDGER2)
state_section = g_strdup (STATE_SECTION_GEN_LEDGER); state_section = g_strdup (STATE_SECTION_GEN_LEDGER);
else if (ledger_type == LD2_SUBACCOUNT) else if (ledger_type == LD2_SUBACCOUNT)
state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", (gchar*)guid_to_string (guid), " w/subaccounts", NULL); {
gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff (guid, guidstr);
state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", guidstr, " w/subaccounts", NULL);
}
else else
state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", (gchar*)guid_to_string (guid), NULL); {
gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff (guid, guidstr);
state_section = g_strconcat (STATE_SECTION_REG_PREFIX, " ", guidstr, NULL);
}
g_object_set (G_OBJECT (view), "state-section", state_section, g_object_set (G_OBJECT (view), "state-section", state_section,
"show-column-menu", FALSE, NULL); "show-column-menu", FALSE, NULL);
@ -680,31 +688,6 @@ gsr2_redraw_all_cb (GncTreeViewSplitReg *view, gpointer user_data)
static void static void
gnc_split_reg2_ld_destroy (GNCLedgerDisplay2 *ledger) gnc_split_reg2_ld_destroy (GNCLedgerDisplay2 *ledger)
{ {
GNCSplitReg2 *gsr = gnc_ledger_display2_get_user_data (ledger);
gchar *state_key;
const GncGUID * guid;
Account * account;
account = gnc_ledger_display2_leader (ledger);
guid = xaccAccountGetGUID (account);
state_key = (gchar*)guid_to_string (guid);
if (gsr)
{
GncTreeModelSplitReg *model;
model = gnc_ledger_display2_get_split_model_register (ledger);
/*FIXME This may not be required
if (model && model->table)
gnc_table_save_state (model->table, state_key);
*/
/*
* Don't destroy the window here any more. The register no longer
* owns it.
*/
}
gnc_ledger_display2_set_user_data (ledger, NULL); gnc_ledger_display2_set_user_data (ledger, NULL);
} }

View File

@ -309,7 +309,7 @@ static void
gnc_save_all_state (gpointer session, gpointer unused) gnc_save_all_state (gpointer session, gpointer unused)
{ {
QofBook *book; QofBook *book;
const gchar *guid_string; gchar guid_string[GUID_ENCODING_LENGTH+1];
const GncGUID *guid; const GncGUID *guid;
GError *error = NULL; GError *error = NULL;
GKeyFile *keyfile = NULL; GKeyFile *keyfile = NULL;
@ -338,7 +338,7 @@ gnc_save_all_state (gpointer session, gpointer unused)
/* Store the book's GncGUID in the top level group */ /* Store the book's GncGUID in the top level group */
book = qof_session_get_book(session); book = qof_session_get_book(session);
guid = qof_entity_get_guid(QOF_INSTANCE(book)); guid = qof_entity_get_guid(QOF_INSTANCE(book));
guid_string = guid_to_string(guid); guid_to_string_buff(guid, guid_string);
g_key_file_set_string(keyfile, STATE_FILE_TOP, STATE_FILE_BOOK_GUID, g_key_file_set_string(keyfile, STATE_FILE_TOP, STATE_FILE_BOOK_GUID,
guid_string); guid_string);

View File

@ -284,11 +284,13 @@ static void dump_split_record(split_record record)
} }
if (record.trans_guid_present) if (record.trans_guid_present)
{ {
DEBUG("Transaction GncGUID: %s", guid_to_string (&(record.trans_guid))); guid_to_string_buff(&record.trans_guid, string_buf);
DEBUG("Transaction GncGUID: %s", string_buf);
} }
if (record.split_guid_present) if (record.split_guid_present)
{ {
DEBUG("Split GncGUID: %s", guid_to_string (&(record.split_guid))); guid_to_string_buff(&record.split_guid, string_buf);
DEBUG("Split GncGUID: %s", string_buf);
} }
if (record.log_date_present) if (record.log_date_present)
{ {
@ -307,7 +309,8 @@ static void dump_split_record(split_record record)
} }
if (record.acc_guid_present) if (record.acc_guid_present)
{ {
DEBUG("Account GncGUID: %s", guid_to_string (&(record.acc_guid))); guid_to_string_buff(&record.trans_guid, string_buf);
DEBUG("Account GncGUID: %s", string_buf);
} }
if (record.acc_name_present) if (record.acc_name_present)
{ {

View File

@ -167,22 +167,22 @@ guid_new_return(void)
return *ret; return *ret;
} }
const char * gchar *
guid_to_string (const GncGUID * guid) guid_to_string (const GncGUID * guid)
{ {
/* We need to malloc here, not 'new' because it will be freed /* We need to malloc here, not 'new' because it will be freed
by the caller which will use free (not delete).*/ by the caller which will use free (not delete).*/
char * ret {reinterpret_cast<char*> (malloc (sizeof (char)*GUID_ENCODING_LENGTH+1))}; gchar * ret {reinterpret_cast<gchar*> (g_malloc (sizeof (gchar)*GUID_ENCODING_LENGTH+1))};
gchar * temp {guid_to_string_buff(guid, ret)}; gchar * temp {guid_to_string_buff (guid, ret)};
if (!temp){ if (!temp){
delete[] ret; g_free (ret);
return temp; return nullptr;
} }
return ret; return ret;
} }
gchar * gchar *
guid_to_string_buff(const GncGUID * guid, char *str) guid_to_string_buff (const GncGUID * guid, gchar *str)
{ {
if (!str || !guid) return NULL; if (!str || !guid) return NULL;

View File

@ -127,15 +127,15 @@ GncGUID *guid_copy (const GncGUID *guid);
* encoding of the id. String encodings of identifiers are hex * encoding of the id. String encodings of identifiers are hex
* numbers printed only with the characters '0' through '9' and * numbers printed only with the characters '0' through '9' and
* 'a' through 'f'. The encoding will always be GUID_ENCODING_LENGTH * 'a' through 'f'. The encoding will always be GUID_ENCODING_LENGTH
* characters long. * characters long (not including the null terminator).
* *
* @param guid The guid to print. * @param guid The guid to print.
* *
* @return A pointer to the starting character of the string. The * @return A pointer to the starting character of the string. The
* returned memory is owned by this routine and may not be freed by * returned memory is owned by the calling routine and must be freed
* the caller. * using g_free.
*/ */
const gchar * guid_to_string (const GncGUID * guid); gchar * guid_to_string (const GncGUID * guid);
/** The guid_to_string_buff() routine puts a null-terminated string /** The guid_to_string_buff() routine puts a null-terminated string
* encoding of the id into the memory pointed at by buff. The * encoding of the id into the memory pointed at by buff. The

View File

@ -1568,9 +1568,9 @@ kvp_value_to_string(const KvpValue *val)
break; break;
case KVP_TYPE_GUID: case KVP_TYPE_GUID:
/* THREAD-UNSAFE */ gchar guidstr[GUID_ENCODING_LENGTH+1];
ctmp = guid_to_string(kvp_value_get_guid(val)); guid_to_string_buff(kvp_value_get_guid(val),guidstr);
tmp2 = g_strdup_printf("KVP_VALUE_GUID(%s)", ctmp ? ctmp : ""); tmp2 = g_strdup_printf("KVP_VALUE_GUID(%s)", guidstr);
return tmp2; return tmp2;
break; break;

View File

@ -691,8 +691,9 @@ qof_instance_print_dirty (const QofInstance *inst, gpointer dummy)
priv = GET_PRIVATE(inst); priv = GET_PRIVATE(inst);
if (priv->dirty) if (priv->dirty)
{ {
printf("%s instance %s is dirty.\n", inst->e_type, gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string(&priv->guid)); guid_to_string_buff(&priv->guid, guidstr);
printf("%s instance %s is dirty.\n", inst->e_type, guidstr);
} }
} }

View File

@ -1779,9 +1779,9 @@ qof_query_printValueForParam (QofQueryPredData *pd, GString * gs)
qof_query_printGuidMatch (pdata->options)); qof_query_printGuidMatch (pdata->options));
for (node = pdata->guids; node; node = node->next) for (node = pdata->guids; node; node = node->next)
{ {
/* THREAD-UNSAFE */ gchar guidstr[GUID_ENCODING_LENGTH+1];
g_string_append_printf (gs, ", guids: %s", guid_to_string_buff ((GncGUID *) node->data,guidstr);
guid_to_string ((GncGUID *) node->data)); g_string_append_printf (gs, ", guids: %s",guidstr);
} }
return; return;
} }

View File

@ -69,16 +69,17 @@ static void test_gnc_guid_copy (void) {
defined in the guid api. We then compare them.*/ defined in the guid api. We then compare them.*/
static void test_gnc_guid_to_string (void) { static void test_gnc_guid_to_string (void) {
GncGUID * guid {guid_malloc()}; GncGUID * guid {guid_malloc()};
gchar guidstrp [GUID_ENCODING_LENGTH+1];
gchar guidstrp2[GUID_ENCODING_LENGTH+1];
g_assert (guid != nullptr); g_assert (guid != nullptr);
guid_replace (guid); guid_replace (guid);
string message {" using guid_to_string (deprecated): "}; string message {" using guid_to_string (deprecated): "};
/*don't free the return value of guid_to_string!*/ guid_to_string_buff (guid,guidstrp);
string guidstr {guid_to_string (guid)}; string guidstr {guidstrp};
g_assert (guidstr.size () == GUID_ENCODING_LENGTH); g_assert (guidstr.size () == GUID_ENCODING_LENGTH);
message += guidstr; message += guidstr;
g_test_message ("%s", message.c_str ()); g_test_message ("%s", message.c_str ());
message = " using guid_to_string_buff: "; message = " using guid_to_string_buff: ";
gchar guidstrp2 [GUID_ENCODING_LENGTH+1];
gchar * ret {guid_to_string_buff (guid, guidstrp2)}; gchar * ret {guid_to_string_buff (guid, guidstrp2)};
g_assert (ret == guidstrp2 + GUID_ENCODING_LENGTH); g_assert (ret == guidstrp2 + GUID_ENCODING_LENGTH);
string guidstr2 {guidstrp2}; string guidstr2 {guidstrp2};

View File

@ -980,7 +980,7 @@ test_binary_to_string( void )
static void static void
test_kvp_value_to_string( void ) test_kvp_value_to_string( void )
{ {
const gchar *str_tmp; gchar guidstr[GUID_ENCODING_LENGTH+1];
gchar *str_tmp2, *str_tmp3; gchar *str_tmp2, *str_tmp3;
gchar *result; gchar *result;
KvpValue *gint64_value; KvpValue *gint64_value;
@ -1038,8 +1038,8 @@ test_kvp_value_to_string( void )
result = kvp_value_to_string( guid_value ); result = kvp_value_to_string( guid_value );
g_assert( result ); g_assert( result );
str_tmp = guid_to_string( kvp_value_get_guid( guid_value ) ); guid_to_string_buff( kvp_value_get_guid( guid_value ), guidstr);
str_tmp2 = g_strdup_printf("KVP_VALUE_GUID(%s)", str_tmp ? str_tmp : ""); str_tmp2 = g_strdup_printf("KVP_VALUE_GUID(%s)", guidstr);
g_assert_cmpstr( result, == , str_tmp2 ); g_assert_cmpstr( result, == , str_tmp2 );
g_free( result ); g_free( result );
g_free( str_tmp2 ); g_free( str_tmp2 );