From patchwork Sat Nov 11 13:57:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zorro Lang X-Patchwork-Id: 10054301 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 424576057F for ; Sat, 11 Nov 2017 13:58:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 400C62A9D9 for ; Sat, 11 Nov 2017 13:58:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22A182A9F4; Sat, 11 Nov 2017 13:58:07 +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 A30F82A9D9 for ; Sat, 11 Nov 2017 13:58:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750778AbdKKN6F (ORCPT ); Sat, 11 Nov 2017 08:58:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58002 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750770AbdKKN6F (ORCPT ); Sat, 11 Nov 2017 08:58:05 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4DE4DC049D49 for ; Sat, 11 Nov 2017 13:58:05 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A04C619A7 for ; Sat, 11 Nov 2017 13:58:04 +0000 (UTC) From: Zorro Lang To: linux-xfs@vger.kernel.org Subject: [PATCH v2] xfsprogs: fix wrong variable type in write_once function Date: Sat, 11 Nov 2017 21:57:59 +0800 Message-Id: <20171111135759.7431-1-zlang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 11 Nov 2017 13:58:05 +0000 (UTC) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The 'Coverity Scan' found a problem in new write_once() function: 272 size_t bytes; 273 bytes = do_pwrite(file->fd, offset, count, count, pwritev2_flags); >>> CID 1420710: Control flow issues (NO_EFFECT) >>> This less-than-zero comparison of an unsigned value is never true. "bytes < 0UL". 274 if (bytes < 0) 275 return -1; That's unreasonable. do_pwrite return 'ssize_t' type value, which can be less than zero, but we use a 'size_t' to get the return value. So change the size_t to ssize_t for it can store the return value correctly. By the chance, correct all 'ssize_t' type problems in pwrite related functions. Signed-off-by: Zorro Lang Reviewed-by: Eric Sandeen --- V2 changed more than V1, as below: 1) The return value type of do_pwritev and do_pwrite, from 'int' to 'ssize_t' 2) The arguments type of do_pwritev and do_pwrite, from 'ssize_t' to 'size_t' Thanks, Zorro io/pwrite.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/io/pwrite.c b/io/pwrite.c index 26f79579..3df976a8 100644 --- a/io/pwrite.c +++ b/io/pwrite.c @@ -61,12 +61,12 @@ pwrite_help(void) } #ifdef HAVE_PWRITEV -static int +static ssize_t do_pwritev( int fd, off64_t offset, - ssize_t count, - ssize_t buffer_size, + size_t count, + size_t buffer_size, int pwritev2_flags) { int vecs = 0; @@ -105,12 +105,12 @@ do_pwritev( #define do_pwritev(fd, offset, count, buffer_size) (0) #endif -static int +static ssize_t do_pwrite( int fd, off64_t offset, - ssize_t count, - ssize_t buffer_size, + size_t count, + size_t buffer_size, int pwritev2_flags) { if (!vectors) @@ -269,7 +269,7 @@ write_once( long long *total, int pwritev2_flags) { - size_t bytes; + ssize_t bytes; bytes = do_pwrite(file->fd, offset, count, count, pwritev2_flags); if (bytes < 0) return -1;