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);
#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,
entity, guid_to_string(guid));
entity, guidstr);
#endif
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 *sf_extension = NULL, *newstyle_filename = NULL;
const gchar *uri, *guid_string;
const gchar *uri;
gchar guid_string[GUID_ENCODING_LENGTH+1];
QofBook *book;
const GncGUID *guid;
GKeyFile *key_file = NULL;
@ -94,7 +95,7 @@ gnc_state_set_base (const QofSession *session)
/* Get the book GncGUID */
book = qof_session_get_book(session);
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))
{

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
* hash. */
gnc_numeric* elem = g_hash_table_lookup(hash, guid);
gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff(guid, guidstr);
if (!elem)
{
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].",
gnc_num_dbg_to_string(*amount),
gnc_numeric_check(*amount),
guid_to_string(guid));
guidstr);
return;
}
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].",
gnc_num_dbg_to_string(*elem),
gnc_numeric_check(*elem),
guid_to_string(guid));
guidstr);
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)
{
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_numeric_check(*elem),
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. */
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(*elem));
}

View File

@ -297,7 +297,7 @@ gnc_is_trans_scm(SCM scm)
void
gnc_split_scm_set_account(SCM split_scm, Account *account)
{
const char *guid_string;
gchar guid_string[GUID_ENCODING_LENGTH+1];
SCM arg;
initialize_scm_functions();
@ -307,7 +307,7 @@ gnc_split_scm_set_account(SCM split_scm, Account *account)
if (account == NULL)
return;
guid_string = guid_to_string(xaccAccountGetGUID(account));
guid_to_string_buff(xaccAccountGetGUID(account), guid_string);
if (guid_string == NULL)
return;
@ -657,6 +657,7 @@ gnc_copy_trans_scm_onto_trans_swap_accounts(SCM trans_scm,
}
else
{
gchar guidstr[GUID_ENCODING_LENGTH+1];
SCM from, to;
SCM map = 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);
from = scm_from_utf8_string(guid_to_string(guid_1));
to = scm_from_utf8_string(guid_to_string(guid_2));
guid_to_string_buff(guid_1, guidstr);
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(to, from), map);

View File

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

View File

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

View File

@ -740,10 +740,10 @@ gnc_schedXaction_end_handler(gpointer data_for_children,
if ( sx->template_acct == NULL )
{
Account *ra = NULL;
const char *id = NULL;
Account *acct = NULL;
sixtp_gdv2 *sixdata = gdata->parsedata;
QofBook *book;
gchar guidstr[GUID_ENCODING_LENGTH+1];
book = sixdata->book;
@ -751,8 +751,7 @@ gnc_schedXaction_end_handler(gpointer data_for_children,
change re: storing template accounts. */
/* Fix: get account with name of our GncGUID from the template
accounts. Make that our template_acct pointer. */
/* THREAD-UNSAFE */
id = guid_to_string( xaccSchedXactionGetGUID( sx ) );
guid_to_string_buff( xaccSchedXactionGetGUID( sx ), guidstr );
ra = gnc_book_get_template_root(book);
if ( ra == NULL )
{
@ -760,15 +759,15 @@ gnc_schedXaction_end_handler(gpointer data_for_children,
xmlFreeNode( tree );
return FALSE;
}
acct = gnc_account_lookup_by_name( ra, id );
acct = gnc_account_lookup_by_name( ra, guidstr );
if ( acct == NULL )
{
g_warning("no template account with name [%s]", id);
g_warning("no template account with name [%s]", guidstr);
xmlFreeNode( tree );
return FALSE;
}
g_debug("template account name [%s] for SX with GncGUID [%s]",
xaccAccountGetName( acct ), id );
xaccAccountGetName( acct ), guidstr );
/* FIXME: free existing template account.
* 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))
{
PINFO("Fixing i-taxtable on entry %s\n",
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(entry))));
gchar guidstr[GUID_ENCODING_LENGTH+1];
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);
gncEntryBeginEdit(entry);
gncEntrySetInvTaxTable(entry, new_tt);
@ -597,8 +598,9 @@ taxtable_scrub_entries (QofInstance * entry_p, gpointer ht_p)
{
if (taxtable_is_grandchild(table))
{
PINFO("Fixing b-taxtable on entry %s\n",
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(entry))));
gchar guidstr[GUID_ENCODING_LENGTH+1];
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);
gncEntryBeginEdit(entry);
gncEntrySetBillTaxTable(entry, new_tt);
@ -656,9 +658,10 @@ taxtable_reset_refcount (gpointer key, gpointer value, gpointer notused)
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",
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(table))),
gncTaxTableGetRefcount(table), count);
guidstr,gncTaxTableGetRefcount(table), count);
gncTaxTableSetRefcount(table, count);
}
}
@ -679,10 +682,11 @@ taxtable_scrub (QofBook *book)
/* destroy the list of "grandchildren" tax tables */
for (node = list; node; node = node->next)
{
gchar guidstr[GUID_ENCODING_LENGTH+1];
table = node->data;
PINFO ("deleting grandchild taxtable: %s\n",
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(table))));
guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(table)),guidstr);
PINFO ("deleting grandchild taxtable: %s\n", guidstr);
/* Make sure the parent has no children */
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");
break;
case KVP_TYPE_GUID:
/* THREAD-UNSAFE */
add_text_to_node(val_node, "guid",
g_strdup(guid_to_string(kvp_value_get_guid(val))));
{
gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff(kvp_value_get_guid(val), guidstr);
add_text_to_node(val_node, "guid", guidstr);
break;
}
case KVP_TYPE_TIMESPEC:
{
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)
{
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";
}

View File

@ -2177,24 +2177,25 @@ gnc_invoice_save_page (InvoiceWindow *iw,
GKeyFile *key_file,
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,
InvoiceDialogTypeasString(iw->dialog_type));
g_key_file_set_string(key_file, group_name, KEY_INVOICE_GUID,
guid_to_string(&iw->invoice_guid));
g_key_file_set_string(key_file, group_name, KEY_INVOICE_GUID, guidstr);
if (gncOwnerGetJob (&(iw->job)))
{
g_key_file_set_string(key_file, group_name, KEY_OWNER_TYPE,
qofOwnerGetType(&iw->job));
g_key_file_set_string(key_file, group_name, KEY_OWNER_GUID,
guid_to_string(gncOwnerGetGUID(&iw->job)));
guid_to_string_buff(gncOwnerGetGUID(&iw->job), guidstr);
g_key_file_set_string(key_file, group_name, KEY_OWNER_GUID, guidstr);
}
else
{
g_key_file_set_string(key_file, group_name, KEY_OWNER_TYPE,
qofOwnerGetType(&iw->owner));
g_key_file_set_string(key_file, group_name, KEY_OWNER_GUID,
guid_to_string(gncOwnerGetGUID(&iw->owner)));
guid_to_string_buff(gncOwnerGetGUID(&iw->owner), guidstr);
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
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
of identifiers are hex numbers printed only with the characters @code{0}
through @code{9} and @code{a} through @code{f}. The encoding will
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
@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;
const GncGUID *guid;
gchar guidstr[GUID_ENCODING_LENGTH+1];
qof_instance_init_data (&sx->inst, GNC_ID_SCHEDXACTION, book);
@ -387,7 +388,8 @@ xaccSchedXactionInit(SchedXaction *sx, QofBook *book)
sx->template_acct = xaccMallocAccount(book);
guid = qof_instance_get_guid( sx );
xaccAccountBeginEdit( sx->template_acct );
xaccAccountSetName( sx->template_acct, guid_to_string( guid ));
guid_to_string_buff( guid, guidstr );
xaccAccountSetName( sx->template_acct, guidstr);
xaccAccountSetCommodity
(sx->template_acct,
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));
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.",
guid_to_string(xaccSplitGetGUID(osplit)),
guidstr,
gnc_commodity_get_mnemonic(split_comm),
gnc_commodity_get_mnemonic(to_commodity)
);

View File

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

View File

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

View File

@ -974,6 +974,7 @@ test_xaccSplitConvertAmount (void)
"GNCXX", "", 1000);
gnc_commodity *gnm = gnc_commodity_new (book, "Gnome, Inc.", "NYSE",
"GNM", "", 1000);
gchar guidstr[GUID_ENCODING_LENGTH+1];
Account *acc = xaccMallocAccount (book);
Account *o_acc = xaccMallocAccount (book);
@ -991,7 +992,8 @@ test_xaccSplitConvertAmount (void)
TestErrorStruct check = { loglevel, logdomain, NULL, 0 };
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 (o_acc, gnaira);
xaccAccountSetCommodity (ya_acc, gnm);

View File

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

View File

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

View File

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

View File

@ -289,6 +289,7 @@ gbv_create_widget(GncBudgetView *view)
GtkTreeIter iter;
GtkWidget* h_separator;
gchar *state_section;
gchar guidstr[GUID_ENCODING_LENGTH+1];
priv = GNC_BUDGET_VIEW_GET_PRIVATE(view);
vbox = GTK_VBOX(view);
@ -315,7 +316,8 @@ gbv_create_widget(GncBudgetView *view)
tree_view = gnc_tree_view_account_new(FALSE);
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_free (state_section);
@ -487,13 +489,16 @@ void
gnc_budget_view_delete_budget(GncBudgetView *view)
{
GncBudgetViewPrivate *priv;
gchar guidstr[GUID_ENCODING_LENGTH+1];
g_return_if_fail(view != NULL);
ENTER("view %p", 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);
LEAVE(" ");

View File

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

View File

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

View File

@ -262,9 +262,17 @@ gsr2_create_table (GNCSplitReg2 *gsr)
if (ledger_type == LD2_GL && model->type == GENERAL_LEDGER2)
state_section = g_strdup (STATE_SECTION_GEN_LEDGER);
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
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,
"show-column-menu", FALSE, NULL);
@ -680,31 +688,6 @@ gsr2_redraw_all_cb (GncTreeViewSplitReg *view, gpointer user_data)
static void
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);
}

View File

@ -309,7 +309,7 @@ static void
gnc_save_all_state (gpointer session, gpointer unused)
{
QofBook *book;
const gchar *guid_string;
gchar guid_string[GUID_ENCODING_LENGTH+1];
const GncGUID *guid;
GError *error = 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 */
book = qof_session_get_book(session);
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,
guid_string);

View File

@ -284,11 +284,13 @@ static void dump_split_record(split_record record)
}
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)
{
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)
{
@ -307,7 +309,8 @@ static void dump_split_record(split_record record)
}
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)
{

View File

@ -167,22 +167,22 @@ guid_new_return(void)
return *ret;
}
const char *
gchar *
guid_to_string (const GncGUID * guid)
{
/* We need to malloc here, not 'new' because it will be freed
by the caller which will use free (not delete).*/
char * ret {reinterpret_cast<char*> (malloc (sizeof (char)*GUID_ENCODING_LENGTH+1))};
gchar * temp {guid_to_string_buff(guid, ret)};
gchar * ret {reinterpret_cast<gchar*> (g_malloc (sizeof (gchar)*GUID_ENCODING_LENGTH+1))};
gchar * temp {guid_to_string_buff (guid, ret)};
if (!temp){
delete[] ret;
return temp;
g_free (ret);
return nullptr;
}
return ret;
}
gchar *
guid_to_string_buff(const GncGUID * guid, char *str)
guid_to_string_buff (const GncGUID * guid, gchar *str)
{
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
* numbers printed only with the characters '0' through '9' and
* '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.
*
* @return A pointer to the starting character of the string. The
* returned memory is owned by this routine and may not be freed by
* the caller.
* returned memory is owned by the calling routine and must be freed
* 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
* 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;
case KVP_TYPE_GUID:
/* THREAD-UNSAFE */
ctmp = guid_to_string(kvp_value_get_guid(val));
tmp2 = g_strdup_printf("KVP_VALUE_GUID(%s)", ctmp ? ctmp : "");
gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff(kvp_value_get_guid(val),guidstr);
tmp2 = g_strdup_printf("KVP_VALUE_GUID(%s)", guidstr);
return tmp2;
break;

View File

@ -691,8 +691,9 @@ qof_instance_print_dirty (const QofInstance *inst, gpointer dummy)
priv = GET_PRIVATE(inst);
if (priv->dirty)
{
printf("%s instance %s is dirty.\n", inst->e_type,
guid_to_string(&priv->guid));
gchar guidstr[GUID_ENCODING_LENGTH+1];
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));
for (node = pdata->guids; node; node = node->next)
{
/* THREAD-UNSAFE */
g_string_append_printf (gs, ", guids: %s",
guid_to_string ((GncGUID *) node->data));
gchar guidstr[GUID_ENCODING_LENGTH+1];
guid_to_string_buff ((GncGUID *) node->data,guidstr);
g_string_append_printf (gs, ", guids: %s",guidstr);
}
return;
}

View File

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

View File

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