From patchwork Thu Feb 14 18:29:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Fasheh X-Patchwork-Id: 2142501 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 877B33FCF6 for ; Thu, 14 Feb 2013 18:29:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934717Ab3BNS3w (ORCPT ); Thu, 14 Feb 2013 13:29:52 -0500 Received: from cantor2.suse.de ([195.135.220.15]:50157 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760806Ab3BNS3w (ORCPT ); Thu, 14 Feb 2013 13:29:52 -0500 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E3CFFA51FF; Thu, 14 Feb 2013 19:29:50 +0100 (CET) Date: Thu, 14 Feb 2013 10:29:50 -0800 From: Mark Fasheh To: linux-btrfs@vger.kernel.org Cc: chris.mason@fusionio.com Subject: btrfs-progs: Fix pointer math in __ino_to_path_fd Message-ID: <20130214182950.GB31017@wotan.suse.de> Reply-To: Mark Fasheh MIME-Version: 1.0 Content-Disposition: inline Organization: SUSE Labs User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We are casting an array of u64 values into a char ** array so when we dereference this array (as a char **) on a 32 bit system we're then re-casting that back to a 32 bit value. This causes problems when we try to print those strings. Signed-off-by: Mark Fasheh --- cmds-inspect.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmds-inspect.c b/cmds-inspect.c index 25b83d2..371bd34 100644 --- a/cmds-inspect.c +++ b/cmds-inspect.c @@ -61,12 +61,15 @@ static int __ino_to_path_fd(u64 inum, int fd, int verbose, const char *prepend) fspath->elem_cnt, fspath->elem_missed); for (i = 0; i < fspath->elem_cnt; ++i) { - char **str = (char **)fspath->val; - str[i] += (unsigned long)fspath->val; + u64 ptr; + char *str; + ptr = (u64)(unsigned long)fspath->val; + ptr += fspath->val[i]; + str = (char *)(unsigned long)ptr; if (prepend) - printf("%s/%s\n", prepend, str[i]); + printf("%s/%s\n", prepend, str); else - printf("%s\n", str[i]); + printf("%s\n", str); } out: