mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
kvp string: allocate enough space
We need to allocate enough space for the terminating null character. Also, I double-checked the documents for std::basic_string::c_str () and verified that it does guarantee the terminating null, so I put a comment in the code that depends on that.
This commit is contained in:
@@ -489,7 +489,7 @@ void
|
||||
gnc_budget_unset_account_period_value(GncBudget *budget, const Account *account,
|
||||
guint period_num)
|
||||
{
|
||||
gchar path_part_one [GUID_ENCODING_LENGTH];
|
||||
gchar path_part_one [GUID_ENCODING_LENGTH + 1];
|
||||
gchar path_part_two [GNC_BUDGET_MAX_NUM_PERIODS_DIGITS];
|
||||
|
||||
g_return_if_fail (budget != NULL);
|
||||
@@ -511,7 +511,7 @@ void
|
||||
gnc_budget_set_account_period_value(GncBudget *budget, const Account *account,
|
||||
guint period_num, gnc_numeric val)
|
||||
{
|
||||
gchar path_part_one [GUID_ENCODING_LENGTH];
|
||||
gchar path_part_one [GUID_ENCODING_LENGTH + 1];
|
||||
gchar path_part_two [GNC_BUDGET_MAX_NUM_PERIODS_DIGITS];
|
||||
|
||||
/* Watch out for an off-by-one error here:
|
||||
@@ -553,7 +553,7 @@ gnc_budget_is_account_period_value_set(const GncBudget *budget,
|
||||
guint period_num)
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
gchar path_part_one [GUID_ENCODING_LENGTH];
|
||||
gchar path_part_one [GUID_ENCODING_LENGTH + 1];
|
||||
gchar path_part_two [GNC_BUDGET_MAX_NUM_PERIODS_DIGITS];
|
||||
gconstpointer ptr = NULL;
|
||||
|
||||
@@ -573,7 +573,7 @@ gnc_budget_get_account_period_value(const GncBudget *budget,
|
||||
guint period_num)
|
||||
{
|
||||
gnc_numeric *numeric = NULL;
|
||||
gchar path_part_one [GUID_ENCODING_LENGTH];
|
||||
gchar path_part_one [GUID_ENCODING_LENGTH + 1];
|
||||
gchar path_part_two [GNC_BUDGET_MAX_NUM_PERIODS_DIGITS];
|
||||
GValue v = G_VALUE_INIT;
|
||||
|
||||
|
||||
@@ -177,7 +177,9 @@ guid_to_string_buff (const GncGUID * guid, gchar *str)
|
||||
|
||||
gnc::GUID temp {*guid};
|
||||
auto val = temp.to_string ();
|
||||
/*We need to be sure to copy the terminating null character.*/
|
||||
/*We need to be sure to copy the terminating null character.
|
||||
* The standard guarantees that std::basic_string::c_str ()
|
||||
* returns with a terminating null character, too.*/
|
||||
std::copy (val.c_str (), val.c_str () + val.size () + 1, str);
|
||||
return str + val.size ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user