From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmyJY-0002kc-Nt for qemu-devel@nongnu.org; Wed, 12 Jun 2013 23:35:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UmyJX-0003Fa-SS for qemu-devel@nongnu.org; Wed, 12 Jun 2013 23:35:08 -0400 Received: from e28smtp02.in.ibm.com ([122.248.162.2]:41001) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmyJX-0003EG-84 for qemu-devel@nongnu.org; Wed, 12 Jun 2013 23:35:07 -0400 Received: from /spool/local by e28smtp02.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 13 Jun 2013 08:57:34 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 639EB3940043 for ; Thu, 13 Jun 2013 09:05:00 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r5D3Z07519923070 for ; Thu, 13 Jun 2013 09:05:00 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r5D3YwQv016167 for ; Thu, 13 Jun 2013 13:34:58 +1000 Message-ID: <51B93DC8.5090705@linux.vnet.ibm.com> Date: Thu, 13 Jun 2013 11:34:32 +0800 From: Wenchao Xia MIME-Version: 1.0 References: <1370674687-13849-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1370674687-13849-5-git-send-email-xiawenc@linux.vnet.ibm.com> <20130611082625.GE18312@stefanha-thinkpad.redhat.com> In-Reply-To: <20130611082625.GE18312@stefanha-thinkpad.redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 04/11] snapshot: new function bdrv_snapshot_find_by_id_and_name() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: kwolf@redhat.com, phrdina@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, dietmar@proxmox.com 于 2013-6-11 16:26, Stefan Hajnoczi 写道: > On Sat, Jun 08, 2013 at 02:58:00PM +0800, Wenchao Xia wrote: >> + if (id && name) { >> + for (i = 0; i < nb_sns; i++) { >> + sn = &sn_tab[i]; >> + if (!strcmp(sn->id_str, id) && !strcmp(sn->name, name)) { >> + *sn_info = *sn; >> + ret = true; >> + break; >> + } >> + } >> + } else if (id) { >> + for (i = 0; i < nb_sns; i++) { >> + sn = &sn_tab[i]; >> + if (!strcmp(sn->id_str, id)) { >> + *sn_info = *sn; >> + ret = true; >> + break; >> + } >> + } >> + } else if (name) { >> + for (i = 0; i < nb_sns; i++) { >> + sn = &sn_tab[i]; >> + if (!strcmp(sn->name, name)) { >> + *sn_info = *sn; >> + ret = true; >> + break; >> + } >> + } >> + } else { >> + /* program error */ >> + abort(); >> + } > > If you respin, this would be a little clearer: > > assert(id || name); > > if (id && name) { > ... > } else if (id) { > ... > } else if (name) { > ... > } > > The advantage is that the assert(3) condition is included in the error > message that gets printed. > > Stefan > OK, will do it in next version. -- Best Regards Wenchao Xia