summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Booth <mbooth@redhat.com>2012-01-17 13:44:29 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-01-23 18:16:13 +0000
commit54912716d0495102808a7a0f719df134a151981e (patch)
tree2e65ae0190cb0a63e749ddf55fd781ee0d87692c
parent7a8b0ead9a5c7835a5d0fcf023e787867d09bbaa (diff)
downloadlibguestfs-54912716d0495102808a7a0f719df134a151981e.tar.gz
libguestfs-54912716d0495102808a7a0f719df134a151981e.tar.xz
libguestfs-54912716d0495102808a7a0f719df134a151981e.zip
c: Allow NULL optargs to be passed to _argv calls
Previously, passing NULL optargs to an _argv call resulted in a segfault. This change causes NULL optargs to be interpreted as no optargs, and to be correctly handled accordingly. (cherry picked from commit fd1a6d8003b29eaec5230f838f673df7cd0e9c86)
-rw-r--r--generator/generator_c.ml15
1 files changed, 15 insertions, 0 deletions
diff --git a/generator/generator_c.ml b/generator/generator_c.ml
index 9cfb2b72..c6962f51 100644
--- a/generator/generator_c.ml
+++ b/generator/generator_c.ml
@@ -994,6 +994,16 @@ trace_send_line (guestfs_h *g)
indent shortname (string_of_errcode errcode)
in
+ let handle_null_optargs optargs shortname =
+ if optargs <> [] then (
+ pr " struct guestfs_%s_argv optargs_null;\n" shortname;
+ pr " if (!optargs) {\n";
+ pr " optargs_null.bitmask = 0;\n";
+ pr " optargs = &optargs_null;\n";
+ pr " }\n\n";
+ )
+ in
+
(* For non-daemon functions, generate a wrapper around each function. *)
List.iter (
fun (shortname, (ret, _, optargs as style), _, _, _, _, _) ->
@@ -1006,6 +1016,9 @@ trace_send_line (guestfs_h *g)
~handle:"g" ~prefix:"guestfs_" ~suffix:"_argv" ~optarg_proto:Argv
shortname style;
pr "{\n";
+
+ handle_null_optargs optargs shortname;
+
pr " int trace_flag = g->trace;\n";
pr " FILE *trace_fp;\n";
(match ret with
@@ -1071,6 +1084,8 @@ trace_send_line (guestfs_h *g)
pr "{\n";
+ handle_null_optargs optargs shortname;
+
(match args with
| [] -> ()
| _ -> pr " struct %s_args args;\n" name