All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Cc: alevy@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 6/7] libcacard/vcard_emul_nss: Assert vreaderOpt isn't null
Date: Fri, 23 May 2014 22:18:50 +0400	[thread overview]
Message-ID: <537F910A.2070902@msgid.tls.msk.ru> (raw)
In-Reply-To: <537F906E.4010101@msgid.tls.msk.ru>

23.05.2014 22:16, Michael Tokarev пишет:
> 23.05.2014 22:09, Michael Tokarev wrote:
>> 23.05.2014 15:24, Markus Armbruster wrote:
>>> It's not locally obvious, and Coverity can't see it either.
>>>
>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>> Reviewed-by: Alon Levy <alevy@redhat.com>
>>> ---
>>>  libcacard/vcard_emul_nss.c | 1 +
>>>  1 file changed, 1 insertion(+)
>>>
>>> diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
>>> index 2048917..4f55e44 100644
>>> --- a/libcacard/vcard_emul_nss.c
>>> +++ b/libcacard/vcard_emul_nss.c
>>> @@ -1181,6 +1181,7 @@ vcard_emul_options(const char *args)
>>>                  vreaderOpt = g_renew(VirtualReaderOptions, opts->vreader,
>>>                                       reader_count);
>>>              }
>>> +            assert(vreaderOpt);
>>>              opts->vreader = vreaderOpt;
>>>              vreaderOpt = &vreaderOpt[opts->vreader_count];
>>>              vreaderOpt->name = g_strndup(name, name_length);
>>
>> Shouldn't the assignment be moved up one line into the if {}
>> statement instead?
> 
> Actually it looks like this code is just buggy, it works for just
> one iteration.  Because at this place, vreaderOpts will be non-NULL
> only if we expanded the array.  If we didn't (we do that in
> READER_STEP increments), we'll be assigning NULL to opts->vreader,
> because vreaderOpt will _really_ be NULL here.

So, the real fix is:

1) drop = NULL at declaration of vreaderOpt;
2) do not mention vreaderOpt inside the if{} statement at
   all, we don't need indirection there;
3) drop this opts->vreader assignment

and ofcourse do not add the assert as in the patch above ;)

/mjt

> One good example when setting initial values like this (for vreaderOpts)
> is a Bad Idea (tm).  If it weren't needlessly NULL initially, compiler
> was able to tell us about using uninitialized variable.
> 
> Thanks,
> 
> /mjt
> 

  reply	other threads:[~2014-05-23 18:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-23 11:24 [Qemu-devel] [PATCH v2 0/7] libcacard: A few simple fixes and cleanups Markus Armbruster
2014-05-23 11:24 ` [Qemu-devel] [PATCH v2 1/7] libcacard/vscclient: Bury some dead code Markus Armbruster
2014-05-23 11:24 ` [Qemu-devel] [PATCH v2 2/7] libcacard: Plug memory leaks around vreader_get_reader_list() Markus Armbruster
2014-05-23 11:24 ` [Qemu-devel] [PATCH v2 3/7] libcacard/vreader: Drop broken recovery from failed assertion Markus Armbruster
2014-05-23 11:24 ` [Qemu-devel] [PATCH v2 4/7] libcacard/vreader: Tighten assertion to clarify intent Markus Armbruster
2014-05-23 11:24 ` [Qemu-devel] [PATCH v2 5/7] libcacard: Convert two leftover realloc() to GLib Markus Armbruster
2014-05-23 11:24 ` [Qemu-devel] [PATCH v2 6/7] libcacard/vcard_emul_nss: Assert vreaderOpt isn't null Markus Armbruster
2014-05-23 18:09   ` Michael Tokarev
2014-05-23 18:16     ` Michael Tokarev
2014-05-23 18:18       ` Michael Tokarev [this message]
2014-05-26  6:16         ` Markus Armbruster
2014-05-23 11:24 ` [Qemu-devel] [PATCH v2 7/7] libcacard/vcard_emul_nss: Drop a redundant conditional Markus Armbruster
2014-05-23 18:20 ` [Qemu-devel] [PATCH v2 0/7] libcacard: A few simple fixes and cleanups Michael Tokarev
2014-05-23 20:54   ` Michael Tokarev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=537F910A.2070902@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=alevy@redhat.com \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.