From patchwork Sat Dec 15 17:49:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Ospite X-Patchwork-Id: 10732281 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 28E7817E6 for ; Sat, 15 Dec 2018 17:49:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DF952A20F for ; Sat, 15 Dec 2018 17:49:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F207C2A226; Sat, 15 Dec 2018 17:49:39 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 912522A222 for ; Sat, 15 Dec 2018 17:49:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726641AbeLORtj (ORCPT ); Sat, 15 Dec 2018 12:49:39 -0500 Received: from mail.ao2.it ([92.243.12.208]:37564 "EHLO ao2.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727206AbeLORtj (ORCPT ); Sat, 15 Dec 2018 12:49:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ao2.it; s=20180927; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=v9ZF1hKl+7QkKozZO+Ett2R6dVNzQitaHmp+DJ4hAls=; b=O5abjAhxxWm8ZWYj22v5whoKpsmtUSSYtss6MxzdxBmvYSunAiihdrLXMWt6kb/pjtl1G7rcVN5zuKVneSA2VFKo6VdU3p9srbKVLXOk21LA37QwqhNebCPx2Gi2gB8ff/tu0YiiJEjBRm/0zsbW6dbzCtFvM+DThcu3daltn2PezSp4Mjt/tA2n33A9WUyhEQu8rar+bp68EeUdFAiiaDUP/HDMrqzP4YSBf8cwmXPAK/mZe6BT5XFEbNcCgXR+tvJuC40CYLelwMZSGCjjdYgkhKMhnac81v5lYLn3L4/jqSg3XYrJHQPbjUuTIcXsVt/62h2S3mkwoOKQxYC9RA==; Received: from localhost ([::1] helo=jcn) by ao2.it with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1gYE3S-00017f-Hv; Sat, 15 Dec 2018 18:48:46 +0100 Received: from ao2 by jcn with local (Exim 4.91) (envelope-from ) id 1gYE4E-00032T-IV; Sat, 15 Dec 2018 18:49:34 +0100 From: Antonio Ospite To: dash@vger.kernel.org Cc: Antonio Ospite Subject: [PATCH 1/2] Fix clang warnings about "string plus integer" Date: Sat, 15 Dec 2018 18:49:31 +0100 Message-Id: <20181215174932.11635-2-ao2@ao2.it> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181215174932.11635-1-ao2@ao2.it> References: <20181215174932.11635-1-ao2@ao2.it> MIME-Version: 1.0 X-Face: z*RaLf`X<@C75u6Ig9}{oW$H;1_\2t5)({*|jhM/Vb;]yA5\I~93>J<_`<4)A{':UrE Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Building with clang results in some warnings about integer values being added to strings: ----------------------------------------------------------------------- eval.c:1138:13: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int] p = " %s" + (1 - sep); ~~~~~~^~~~~~~~~~~ eval.c:1138:13: note: use array indexing to silence this warning p = " %s" + (1 - sep); ^ & [ ] 1 warning generated. ... jobs.c:1424:16: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int] str = "\"}" + !(quoted & 1); ~~~~~~^~~~~~~~~~~~~~~ jobs.c:1424:16: note: use array indexing to silence this warning str = "\"}" + !(quoted & 1); ^ & [ ] 1 warning generated. ----------------------------------------------------------------------- While the code itself is fine and the warnings are indeed harmless, fixing them also makes the semantic more explicit: what it is actually being increased is the address which points to the start of the string in order to skip the initial character when some conditions are met. Signed-off-by: Antonio Ospite --- src/eval.c | 3 ++- src/jobs.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/eval.c b/src/eval.c index f45e2e2..5074aa9 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1135,7 +1135,8 @@ eprintlist(struct output *out, struct strlist *sp, int sep) while (sp) { const char *p; - p = " %s" + (1 - sep); + p = " %s"; + p += (1 - sep); sep |= 1; outfmt(out, p, sp->text); sp = sp->next; diff --git a/src/jobs.c b/src/jobs.c index f3a0d80..26a6248 100644 --- a/src/jobs.c +++ b/src/jobs.c @@ -1421,7 +1421,8 @@ cmdputs(const char *s) str = "${"; goto dostr; case CTLENDVAR: - str = "\"}" + !(quoted & 1); + str = "\"}"; + str += !(quoted & 1); quoted >>= 1; subtype = 0; goto dostr;