[glibmm/wip/dboles/Binding-master: 1/3] Binding: no point to set target value if got false
- From: Daniel Boles <dboles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm/wip/dboles/Binding-master: 1/3] Binding: no point to set target value if got false
- Date: Sat, 9 Nov 2019 20:02:56 +0000 (UTC)
commit cecbf3c66aa016033207668179a83b3138c8ad0d
Author: Daniel Boles <dboles src gmail com>
Date: Sat Nov 9 19:43:39 2019 +0000
Binding: no point to set target value if got false
If we return false, GBinding ignores target GValue, so there’s no point
setting it. Besides, if the transform function returned false, that says
they couldn't calculate a target value, so they shouldn’t assign to `to`
I default-construct primitive `T_to`s in case anyone *was* reading those
for some daft reason, so they get a zero-initialised value instead of UB
glib/src/binding.hg | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/glib/src/binding.hg b/glib/src/binding.hg
index 840b0b62..7431a374 100644
--- a/glib/src/binding.hg
+++ b/glib/src/binding.hg
@@ -413,14 +413,16 @@ private:
{
Glib::Value<T_from> from_glib_value;
from_glib_value.init(from_value);
+ T_to to{};
+
+ if (!typed_transform(from_glib_value.get(), to))
+ return false;
+
Glib::Value<T_to> to_glib_value;
to_glib_value.init(to_value);
- T_to to = to_glib_value.get();
-
- const bool result = typed_transform(from_glib_value.get(), to);
to_glib_value.set(to);
g_value_copy(to_glib_value.gobj(), to_value);
- return result;
+ return true;
}
private:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]