From patchwork Mon Apr 17 03:26:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9683487 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B767C600C5 for ; Mon, 17 Apr 2017 03:27:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A85EA26490 for ; Mon, 17 Apr 2017 03:27:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D40327F2B; Mon, 17 Apr 2017 03:27:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E940D26490 for ; Mon, 17 Apr 2017 03:27:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932615AbdDQD05 (ORCPT ); Sun, 16 Apr 2017 23:26:57 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:62053 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S932558AbdDQD0w (ORCPT ); Sun, 16 Apr 2017 23:26:52 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="17809860" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 17 Apr 2017 11:26:50 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 44EBC4D14A5C; Mon, 17 Apr 2017 11:26:48 +0800 (CST) Received: from localhost.localdomain (10.167.226.34) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 17 Apr 2017 11:26:52 +0800 From: Qu Wenruo To: , Subject: [PATCH 5/9] btrfs-progs: utils: Introduce new function arg_strtou32 Date: Mon, 17 Apr 2017 11:26:38 +0800 Message-ID: <20170417032642.30770-6-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170417032642.30770-1-quwenruo@cn.fujitsu.com> References: <20170417032642.30770-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.34] X-yoursite-MailScanner-ID: 44EBC4D14A5C.A0AE8 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This function is just calling arg_strtou64() and then do extra UINT32_MAX check. Signed-off-by: Qu Wenruo --- utils-lib.c | 15 +++++++++++++++ utils.h | 1 + 2 files changed, 16 insertions(+) diff --git a/utils-lib.c b/utils-lib.c index 044f93fc..544f6750 100644 --- a/utils-lib.c +++ b/utils-lib.c @@ -44,6 +44,21 @@ u64 arg_strtou64(const char *str) } /* + * u32 version of arg_strtou*() + */ +u32 arg_strtou32(const char *str) +{ + u64 tmp; + + tmp = arg_strtou64(str); + if (tmp >= UINT32_MAX) { + fprintf(stderr, "ERROR: %s is too large.\n", str); + exit(1); + } + return (u32)tmp; +} + +/* * For a given: * - file or directory return the containing tree root id * - subvolume return its own tree id diff --git a/utils.h b/utils.h index 24d0a200..f6deb26c 100644 --- a/utils.h +++ b/utils.h @@ -94,6 +94,7 @@ const char *pretty_size_mode(u64 size, unsigned mode); u64 parse_size(char *s); u64 parse_qgroupid(const char *p); u64 arg_strtou64(const char *str); +u32 arg_strtou32(const char *str); int arg_copy_path(char *dest, const char *src, int destlen); int open_file_or_dir(const char *fname, DIR **dirstream); int open_file_or_dir3(const char *fname, DIR **dirstream, int open_flags);