All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools: libxl: directly initialise saved_* in _libxl_types.c
@ 2015-01-08 10:57 Ian Campbell
  2015-01-08 11:18 ` Wei Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Campbell @ 2015-01-08 10:57 UTC (permalink / raw)
  To: xen-devel; +Cc: wei.liu2, ian.jackson, Ian Campbell

Coverity complains:
> /tools/libxl/_libxl_types.c: 9194 in libxl__device_channel_parse_json()
> 9188             }
> 9189             x = libxl__json_map_get("connection.socket", o, JSON_MAP);
> 9190             if (x) {
> 9191                 libxl_device_channel_init_connection(p, LIBXL_CHANNEL_CONNECTION_SOCKET);
> 9192                 {
> 9193                     const libxl__json_object *saved_path = NULL;
> >>>     CID 1261758:  Unused value  (UNUSED_VALUE)
> >>>     Value from "x" is assigned to "saved_path" here, but that
> >>>     stored value is not used before it is overwritten.
> 9194                     saved_path = x;
> 9195                     x = libxl__json_map_get("path", x, JSON_STRING | JSON_NULL);
> 9196                     if (x) {
> 9197                         rc = libxl__string_parse_json(gc, x, &p->u.socket.path);
> 9198                         if (rc)
> 9199                             goto out;

Which we can avoid by initialising saved_%s as we define it. Resulting
in numerous instances of the generated code changing like this:
         if (x) {
             libxl_channelinfo_init_connection(p, LIBXL_CHANNEL_CONNECTION_PTY);
             {
-                const libxl__json_object *saved_path = NULL;
-                saved_path = x;
+                const libxl__json_object *saved_path = x;
                 x = libxl__json_map_get("path", x, JSON_STRING | JSON_NULL);
                 if (x) {
                     rc = libxl__string_parse_json(gc, x, &p->u.pty.path);

CID: 1261758, 1261759 (and I would have expected others, but not
seeing them for some reason).

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/libxl/gentypes.py |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py
index 3e73821..d9e14fd 100644
--- a/tools/libxl/gentypes.py
+++ b/tools/libxl/gentypes.py
@@ -432,8 +432,7 @@ def libxl_C_type_parse_json(ty, w, v, indent = "    ", parent = None, discrimina
         for f in [f for f in ty.fields if not f.const and not f.type.private]:
             saved_var_name = "saved_%s" % f.name
             s += "{\n"
-            s += "    const libxl__json_object *%s = NULL;\n" % saved_var_name
-            s += "    %s = x;\n" % saved_var_name
+            s += "    const libxl__json_object *%s = x;\n" % saved_var_name
             if isinstance(f.type, idl.KeyedUnion):
                 for x in f.type.fields:
                     s += "    x = libxl__json_map_get(\"%s\", %s, JSON_MAP);\n" % \
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tools: libxl: directly initialise saved_* in _libxl_types.c
  2015-01-08 10:57 [PATCH] tools: libxl: directly initialise saved_* in _libxl_types.c Ian Campbell
@ 2015-01-08 11:18 ` Wei Liu
  2015-01-12 16:30   ` Ian Campbell
  0 siblings, 1 reply; 3+ messages in thread
From: Wei Liu @ 2015-01-08 11:18 UTC (permalink / raw)
  To: Ian Campbell; +Cc: wei.liu2, ian.jackson, xen-devel

On Thu, Jan 08, 2015 at 10:57:47AM +0000, Ian Campbell wrote:
> Coverity complains:
> > /tools/libxl/_libxl_types.c: 9194 in libxl__device_channel_parse_json()
> > 9188             }
> > 9189             x = libxl__json_map_get("connection.socket", o, JSON_MAP);
> > 9190             if (x) {
> > 9191                 libxl_device_channel_init_connection(p, LIBXL_CHANNEL_CONNECTION_SOCKET);
> > 9192                 {
> > 9193                     const libxl__json_object *saved_path = NULL;
> > >>>     CID 1261758:  Unused value  (UNUSED_VALUE)
> > >>>     Value from "x" is assigned to "saved_path" here, but that
> > >>>     stored value is not used before it is overwritten.
> > 9194                     saved_path = x;
> > 9195                     x = libxl__json_map_get("path", x, JSON_STRING | JSON_NULL);
> > 9196                     if (x) {
> > 9197                         rc = libxl__string_parse_json(gc, x, &p->u.socket.path);
> > 9198                         if (rc)
> > 9199                             goto out;
> 
> Which we can avoid by initialising saved_%s as we define it. Resulting
> in numerous instances of the generated code changing like this:
>          if (x) {
>              libxl_channelinfo_init_connection(p, LIBXL_CHANNEL_CONNECTION_PTY);
>              {
> -                const libxl__json_object *saved_path = NULL;
> -                saved_path = x;
> +                const libxl__json_object *saved_path = x;
>                  x = libxl__json_map_get("path", x, JSON_STRING | JSON_NULL);
>                  if (x) {
>                      rc = libxl__string_parse_json(gc, x, &p->u.pty.path);
> 
> CID: 1261758, 1261759 (and I would have expected others, but not
> seeing them for some reason).
> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

Acked-by: Wei Liu <wei.liu2@citrix.com>

> ---
>  tools/libxl/gentypes.py |    3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py
> index 3e73821..d9e14fd 100644
> --- a/tools/libxl/gentypes.py
> +++ b/tools/libxl/gentypes.py
> @@ -432,8 +432,7 @@ def libxl_C_type_parse_json(ty, w, v, indent = "    ", parent = None, discrimina
>          for f in [f for f in ty.fields if not f.const and not f.type.private]:
>              saved_var_name = "saved_%s" % f.name
>              s += "{\n"
> -            s += "    const libxl__json_object *%s = NULL;\n" % saved_var_name
> -            s += "    %s = x;\n" % saved_var_name
> +            s += "    const libxl__json_object *%s = x;\n" % saved_var_name
>              if isinstance(f.type, idl.KeyedUnion):
>                  for x in f.type.fields:
>                      s += "    x = libxl__json_map_get(\"%s\", %s, JSON_MAP);\n" % \
> -- 
> 1.7.10.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tools: libxl: directly initialise saved_* in _libxl_types.c
  2015-01-08 11:18 ` Wei Liu
@ 2015-01-12 16:30   ` Ian Campbell
  0 siblings, 0 replies; 3+ messages in thread
From: Ian Campbell @ 2015-01-12 16:30 UTC (permalink / raw)
  To: Wei Liu; +Cc: ian.jackson, xen-devel

On Thu, 2015-01-08 at 11:18 +0000, Wei Liu wrote:

> Acked-by: Wei Liu <wei.liu2@citrix.com>
> 

Applied, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-01-12 16:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-08 10:57 [PATCH] tools: libxl: directly initialise saved_* in _libxl_types.c Ian Campbell
2015-01-08 11:18 ` Wei Liu
2015-01-12 16:30   ` Ian Campbell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.