[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] uml_conf.c: don't return an uninitialized pointer



Daniel P. Berrange wrote:

> On Thu, Sep 03, 2009 at 12:07:14PM +0200, Jim Meyering wrote:
>> Another "real" bug:
>>
>> >From 6697607bf0b023ffb692576b31d652d10719b08a Mon Sep 17 00:00:00 2001
>> From: Jim Meyering <meyering redhat com>
>> Date: Thu, 3 Sep 2009 12:05:52 +0200
>> Subject: [PATCH] uml_conf.c: don't return an uninitialized pointer
>>
>> * src/uml_conf.c (umlBuildCommandLineChr): Initialize "ret" also
>> in the final switch cases.
>> ---
>>  src/uml_conf.c |    1 +
>>  1 files changed, 1 insertions(+), 0 deletions(-)
>>
>> diff --git a/src/uml_conf.c b/src/uml_conf.c
>> index 838fedd..2e9c25c 100644
>> --- a/src/uml_conf.c
>> +++ b/src/uml_conf.c
>> @@ -331,6 +331,7 @@ umlBuildCommandLineChr(virConnectPtr conn,
>>      default:
>>          umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
>>                         _("unsupported chr device type %d"), def->type);
>> +        ret = NULL;
>>          break;
>>      }
>
> I think this would be better changing the initial declartion to be
> initializing to NULL too.

Actually I did that first, but then un-did it in favor
of the change above.  Why?  because that initialization could
mask a failure to initialize in a new case.

With per-case initialization, we'd detect the bug at
compile/static-analysis time.  With the up-front unconditional
initialization, we cannot, and would have to rely on testing to find it.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]