From patchwork Mon Oct 29 17:53:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 1665061 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 EC1EC3FCF7 for ; Mon, 29 Oct 2012 17:52:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760132Ab2J2Rws (ORCPT ); Mon, 29 Oct 2012 13:52:48 -0400 Received: from mail-ee0-f46.google.com ([74.125.83.46]:36468 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760072Ab2J2Rwp (ORCPT ); Mon, 29 Oct 2012 13:52:45 -0400 Received: by mail-ee0-f46.google.com with SMTP id b15so2229913eek.19 for ; Mon, 29 Oct 2012 10:52:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=7XUbgWlYrfS6VIp48k8Lw2IZCZc4SQFW1YJs0xd2CS4=; b=zufCa1MYRhl1f5KBp7DnwftdaCj7W58SjDLem8jhukyvibYb7Dfi4x0gZnKA4lwhbe qcO6gsK1Q1bsANdaAqLCXeG3Xdua0x3nYDASPL/j2CCjsNuJkHXnSLxDZt4Yk+M8N/DF k1o124fvau9q17IQhymnhL4vIpJkCQwNcb+B5+RxwJKRw2KkbdDYIorCaE8Re3iJ48qv 146lHqz9Nvp4Uq+03JuqQvH18d7JZxDo3yRjImeRCfd109Ac7dXSgGo5YRMFcHGBuPGL xcJzCoBJmnRUPs7CbNxsk9C9xKlAslud1+Yw0wswhXJ/K40fPWSzvNEUi6lz2wzSbeAb AmRA== Received: by 10.14.175.71 with SMTP id y47mr63635721eel.36.1351533164501; Mon, 29 Oct 2012 10:52:44 -0700 (PDT) Received: from venice..bhome (host103-133-static.242-95-b.business.telecomitalia.it. [95.242.133.103]) by mx.google.com with ESMTPS id k2sm24096182eep.15.2012.10.29.10.52.43 (version=SSLv3 cipher=OTHER); Mon, 29 Oct 2012 10:52:44 -0700 (PDT) From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Stefan Behrens , Wang Sheng-Hui Subject: [PATCH 2/4] parse_size(): replace atoll() with strtoull() Date: Mon, 29 Oct 2012 18:53:18 +0100 Message-Id: <1351533200-5703-3-git-send-email-kreijack@inwind.it> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1351533200-5703-1-git-send-email-kreijack@inwind.it> References: <1351533200-5703-1-git-send-email-kreijack@inwind.it> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Replace the function atoll with strtoull(); Check that the suffix for the parse_size() input is of only one character. Signed-off-by: Goffredo Baroncelli --- utils.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/utils.c b/utils.c index 705be7b..aa2e574 100644 --- a/utils.c +++ b/utils.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1222,12 +1223,18 @@ scan_again: u64 parse_size(char *s) { - int len = strlen(s); + int i; char c; u64 mult = 1; - if (!isdigit(s[len - 1])) { - c = tolower(s[len - 1]); + for (i=0 ; s[i] && isdigit(s[i]) ; i++) ; + if (!i) { + fprintf(stderr, "ERROR: size value is empty\n"); + exit(50); + } + + if (s[i]) { + c = tolower(s[i]); switch (c) { case 'g': mult *= 1024; @@ -1238,11 +1245,17 @@ u64 parse_size(char *s) case 'b': break; default: - fprintf(stderr, "Unknown size descriptor %c\n", c); + fprintf(stderr, "ERROR: Unknown size descriptor " + "'%c'\n", c); exit(1); } - s[len - 1] = '\0'; } - return atoll(s) * mult; + if (s[i] && s[i+1]) { + fprintf(stderr, "ERROR: Illegal suffix contains " + "character '%c' in wrong position\n", + s[i+1]); + exit(51); + } + return strtoull(s, NULL, 10) * mult; }