After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 618201 - Initialize return value when a callback throws
Initialize return value when a callback throws
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2010-05-09 20:33 UTC by Owen Taylor
Modified: 2010-05-13 14:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Initialize return value when a callback throws (6.11 KB, patch)
2010-05-09 20:33 UTC, Owen Taylor
committed Details | Review

Description Owen Taylor 2010-05-09 20:33:21 UTC
If a callback throws an exception (or argument conversion fails), we
still need to return something to C. Currently the return value is
left uninitialized, and is junk memory.

Initialize the return value to 0/0.0/NULL depending on the type.
This might be an invalid return value or cause the caller to
segfault in certain cases, but we can't really do better.
Comment 1 Owen Taylor 2010-05-09 20:33:23 UTC
Created attachment 160671 [details] [review]
Initialize return value when a callback throws
Comment 2 Colin Walters 2010-05-10 11:34:04 UTC
Review of attachment 160671 [details] [review]:

::: gi/arg.c
@@ +1130,3 @@
+ * is. It basically boils down to memset(arg, 0, sizeof(*arg)), but
+ * to return something to C. This function defines what that something
+/* If a callback function with a return value throws, we still have

Is there a reason for this over just memset (arg, 0, sizeof(*arg)) ?
Comment 3 Owen Taylor 2010-05-10 11:59:18 UTC
Doesn't the comment(In reply to comment #2)
> Review of attachment 160671 [details] [review]:
> 
> ::: gi/arg.c
> @@ +1130,3 @@
> + * is. It basically boils down to memset(arg, 0, sizeof(*arg)), but
> + * to return something to C. This function defines what that something
> +/* If a callback function with a return value throws, we still have
> 
> Is there a reason for this over just memset (arg, 0, sizeof(*arg)) ?

Doesn't the comment go on to explain that?

 A) I don't completely trust libffi to always provide a sizeof(GArgument) return buffer if the return value is smaller. I don't think it's documented to do that though reading the x86 implementation it does look like it.

 B) Having all the cases would theoretically give us the ability to do return something other than bitwise zero if appropriate. E.g., to return an empty hash table. (Not having allow-none for return annotations makes it a bit hard to know if we ever would want to do that.)
Comment 4 Colin Walters 2010-05-10 13:30:57 UTC
Review of attachment 160671 [details] [review]:

Ok, makes sense, thanks!
Comment 5 Owen Taylor 2010-05-13 14:13:29 UTC
Attachment 160671 [details] pushed as d3983b6 - Initialize return value when a callback throws