[augeas-devel] [PATCH] compile_exp: don't return an uninitialized pointer upon failure

Jim Meyering jim at meyering.net
Fri Apr 6 11:01:39 UTC 2012


I wrote this patch back in December, but apparently never posted it.
Here you go:

>From 41c8facd83f6497ded1f42163f3b472124f75f14 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Fri, 23 Dec 2011 23:19:41 +0100
Subject: [PATCH] compile_exp: don't return an uninitialized pointer upon
 failure

As a result of its improved flow analysis gcc-4.7.0 20111202 reported:

  syntax.c: In function 'compile_exp':
  syntax.c:1694:5: warning: 'v' may be used uninitialized in this \
  function [-Wmaybe-uninitialized]

However, compile_exp calls many functions that return values that are
then assigned to "v".  Only two of those had a problem: in each there
is an error path by which the returned pointer is not initialized.
* src/syntax.c (compile_concat): Initialize "v".
(compile_minus): Likewise.
---
 src/syntax.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/syntax.c b/src/syntax.c
index 2df4947..0fead52 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -1443,6 +1443,7 @@ static struct value *compile_minus(struct term *exp, struct ctx *ctx) {
             v->regexp = re;
         }
     } else {
+        v = NULL;
         fatal_error(info, "Tried to subtract a %s and a %s to yield a %s",
                     type_name(exp->left->type), type_name(exp->right->type),
                     type_name(t));
@@ -1549,6 +1550,7 @@ static struct value *compile_concat(struct term *exp, struct ctx *ctx) {
         struct lens *l2 = v2->lens;
         v = lns_make_concat(ref(info), ref(l1), ref(l2), LNS_TYPE_CHECK(ctx));
     } else {
+        v = NULL;
         fatal_error(info, "Tried to concat a %s and a %s to yield a %s",
                     type_name(exp->left->type), type_name(exp->right->type),
                     type_name(t));
--
1.7.10.rc4




More information about the augeas-devel mailing list