From patchwork Mon Feb 25 22:54:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 2182051 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id E2DC6DF230 for ; Mon, 25 Feb 2013 21:55:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759673Ab3BYVzT (ORCPT ); Mon, 25 Feb 2013 16:55:19 -0500 Received: from nat-pool-rdu.redhat.com ([66.187.233.202]:39429 "EHLO bp-05.lab.msp.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754434Ab3BYVzP (ORCPT ); Mon, 25 Feb 2013 16:55:15 -0500 Received: by bp-05.lab.msp.redhat.com (Postfix, from userid 0) id 4E4701E0A91; Mon, 25 Feb 2013 16:54:54 -0600 (CST) From: Eric Sandeen To: linux-btrfs@vger.kernel.org Cc: Eric Sandeen Subject: [PATCH 02/17] btrfs-progs: fix btrfs_get_subvol cut/paste error Date: Mon, 25 Feb 2013 16:54:35 -0600 Message-Id: <1361832890-40921-3-git-send-email-sandeen@redhat.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1361832890-40921-1-git-send-email-sandeen@redhat.com> References: <1361832890-40921-1-git-send-email-sandeen@redhat.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org in btrfs_get_subvol(), there is a cut and paste error: if (ri->full_path) the_ri->full_path = strdup(ri->full_path); else the_ri->name = NULL; It should be setting the_ri->full_path to NULL here. Do it in a function instead of the cpoy & paste to avoid future errors. Signed-off-by: Eric Sandeen --- btrfs-list.c | 22 ++++++++++------------ 1 files changed, 10 insertions(+), 12 deletions(-) diff --git a/btrfs-list.c b/btrfs-list.c index d02d620..ab9179f 100644 --- a/btrfs-list.c +++ b/btrfs-list.c @@ -1515,6 +1515,13 @@ int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set, return 0; } +char *strdup_or_null(const char *s) +{ + if (!s) + return NULL; + return strdup(s); +} + int btrfs_get_subvol(int fd, struct root_info *the_ri) { int ret = 1, rr; @@ -1537,18 +1544,9 @@ int btrfs_get_subvol(int fd, struct root_info *the_ri) } if (!comp_entry_with_rootid(the_ri, ri, 0)) { memcpy(the_ri, ri, offsetof(struct root_info, path)); - if (ri->path) - the_ri->path = strdup(ri->path); - else - the_ri->path = NULL; - if (ri->name) - the_ri->name = strdup(ri->name); - else - the_ri->name = NULL; - if (ri->full_path) - the_ri->full_path = strdup(ri->full_path); - else - the_ri->name = NULL; + the_ri->path = strdup_or_null(ri->path); + the_ri->name = strdup_or_null(ri->name); + the_ri->full_path = strdup_or_null(ri->full_path); ret = 0; break; }