From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmJuR-0001bj-3h for qemu-devel@nongnu.org; Tue, 11 Jun 2013 04:26:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UmJuP-0002nZ-PR for qemu-devel@nongnu.org; Tue, 11 Jun 2013 04:26:31 -0400 Received: from mail-ea0-x236.google.com ([2a00:1450:4013:c01::236]:33087) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmJuP-0002nO-I4 for qemu-devel@nongnu.org; Tue, 11 Jun 2013 04:26:29 -0400 Received: by mail-ea0-f182.google.com with SMTP id d10so2192655eaj.27 for ; Tue, 11 Jun 2013 01:26:28 -0700 (PDT) Date: Tue, 11 Jun 2013 10:26:25 +0200 From: Stefan Hajnoczi Message-ID: <20130611082625.GE18312@stefanha-thinkpad.redhat.com> References: <1370674687-13849-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1370674687-13849-5-git-send-email-xiawenc@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1370674687-13849-5-git-send-email-xiawenc@linux.vnet.ibm.com> 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: Wenchao Xia 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 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