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:
lmat
2017-11-28 15:44:20 -05:00
parent 5b03182963
commit 4a88f05d11
2 changed files with 7 additions and 5 deletions

View File

@@ -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;

View File

@@ -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 ();
}