From patchwork Thu Nov 23 14:04:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17161 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id EFFEB80961; Thu, 23 Nov 2017 15:06:28 +0100 (CET) Authentication-Results: open-mesh.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=openmesh-com.20150623.gappssmtp.com header.i=@openmesh-com.20150623.gappssmtp.com header.b="saQl9SiS"; dkim-atps=neutral Received-SPF: None (mailfrom) identity=mailfrom; client-ip=2607:f8b0:400d:c0d::243; helo=mail-qt0-x243.google.com; envelope-from=sven.eckelmann@openmesh.com; receiver= Received: from mail-qt0-x243.google.com (mail-qt0-x243.google.com [IPv6:2607:f8b0:400d:c0d::243]) by open-mesh.org (Postfix) with ESMTPS id 00E388065C for ; Thu, 23 Nov 2017 15:05:39 +0100 (CET) Received: by mail-qt0-x243.google.com with SMTP id r58so28093972qtc.0 for ; Thu, 23 Nov 2017 06:05:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openmesh-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OqY7lIAFQeH4Pc/H9yP0kreTqpver3+LzjQ9csOYEjw=; b=saQl9SiSHZCJ5Ts335y+fkXwNf6k2wRZGzfSSHFQz9JnZwxl1a4f9H+M6hqaQ76A2B W22HR+iMafArbpEKrIfQ5tJEwfGZ9HnA/TgSPuf46dBvlKksMKAC4ewj0//uPoNPXE2X xKmNFDChU89+K4oc67xvHnVD//hWFWrEC2N7hdkg2vrfEP/agTk/qTVCy1xgQSbhvdFI 33EvUD52alLqjYnlVtprEZ4a3LnRy2X5HZlu2ZfsijDGWq8EyaR9uFVbjncW4FnnluRI oY5HrUFQ7ljqGgZn75tPSZoUi6CinglQenJLnzKdxBVvURJ6tYq5HWAdwvHKdt8eb7CO HhTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OqY7lIAFQeH4Pc/H9yP0kreTqpver3+LzjQ9csOYEjw=; b=gcjGEpLLkWv6NjoAF7V0lLAtRJhDiLgPWokvQFmDwXP+FioWvz7a6fpggDoqgUc8oK xJQIHA5l3WaRaTeh+ZSwTARju6PiqmcAAipX0/WBSCpOBq9lFm/dzEn9XWVPG6usff00 vcE2ISyBs80HXWx0s8YMzNwPfgo6s9XW0B4HRAzz5q0dUnGVZ1XVwrYCB8+diOkrsqBF 6DA+FNmJN8gLD8S/+O57TFPLy0sWS8/WOXxx7wnVLJfjG8qrijP0GEG4k+UNJpug35z3 Le1Ms/YSrcdMnbxTGcP/baAjUBH6qhhIehxtmvR0T2P4Uh8Zv0RnfvUAZ/tLF7Vxp1E6 hhDg== X-Gm-Message-State: AJaThX757dZeLPIdjBpIFX0XvnC6VqhTJiq2zbO7Pwr4iYl0HDuZPlf0 8xnP14ARduVomRKyDbNVnbPE4pXI X-Google-Smtp-Source: AGs4zMb9LgdvlEYHaPzPdzp5c4+2vf/Jrz/hVCdpFzL7o+T0MW1S2PcLidVS99dGLeizWdol5ifyOg== X-Received: by 10.237.34.193 with SMTP id q1mr37451375qtc.78.1511445938420; Thu, 23 Nov 2017 06:05:38 -0800 (PST) Received: from sven-desktop.home.narfation.org (p2003007C6F53F7FA6FAE965552C91071.dip0.t-ipconnect.de. [2003:7c:6f53:f7fa:6fae:9655:52c9:1071]) by smtp.gmail.com with ESMTPSA id j7sm12759037qth.25.2017.11.23.06.05.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Nov 2017 06:05:37 -0800 (PST) From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 23 Nov 2017 15:04:44 +0100 Message-Id: <20171123140444.17119-11-sven.eckelmann@openmesh.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171123140444.17119-1-sven.eckelmann@openmesh.com> References: <20171123140444.17119-1-sven.eckelmann@openmesh.com> Subject: [B.A.T.M.A.N.] [PATCH 10/10] batctl: Simplify concatenation of pathnames X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Cc: Sven Eckelmann Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" The combination of strncpy and strncat is hard to read and it is rather easy to introduce some kind of problems when using that. The usage of snprintf simplifies it slightly. Signed-off-by: Sven Eckelmann --- bat-hosts.c | 4 +--- functions.c | 8 ++------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/bat-hosts.c b/bat-hosts.c index b530243..54b0a18 100644 --- a/bat-hosts.c +++ b/bat-hosts.c @@ -194,9 +194,7 @@ void bat_hosts_init(int read_opt) if (!homedir) continue; - strncpy(confdir, homedir, CONF_DIR_LEN); - confdir[CONF_DIR_LEN - 1] = '\0'; - strncat(confdir, &bat_hosts_path[i][1], CONF_DIR_LEN - strlen(confdir) - 1); + snprintf(confdir, CONF_DIR_LEN, "%s%s", homedir, &bat_hosts_path[i][1]); } else { strncpy(confdir, bat_hosts_path[i], CONF_DIR_LEN); confdir[CONF_DIR_LEN - 1] = '\0'; diff --git a/functions.c b/functions.c index 868e0ae..8bcf52d 100644 --- a/functions.c +++ b/functions.c @@ -208,9 +208,7 @@ int read_file(const char *dir, const char *fname, int read_opt, if (read_opt & USE_BAT_HOSTS) bat_hosts_init(read_opt); - strncpy(full_path, dir, sizeof(full_path)); - full_path[sizeof(full_path) - 1] = '\0'; - strncat(full_path, fname, sizeof(full_path) - strlen(full_path) - 1); + snprintf(full_path, sizeof(full_path), "%s%s", dir, fname); open: line = 0; @@ -349,9 +347,7 @@ int write_file(const char *dir, const char *fname, const char *arg1, char full_path[500]; ssize_t write_len; - strncpy(full_path, dir, sizeof(full_path)); - full_path[sizeof(full_path) - 1] = '\0'; - strncat(full_path, fname, sizeof(full_path) - strlen(full_path) - 1); + snprintf(full_path, sizeof(full_path), "%s%s", dir, fname); fd = open(full_path, O_WRONLY);