Tarantool development patches archive
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: tml <tarantool-patches@dev.tarantool.org>
Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>,
	Alexander Turenko <alexander.turenko@tarantool.org>
Subject: [Tarantool-patches] [PATCH 4/6] xlog: use PATH_MAX for filename
Date: Thu, 18 Jun 2020 01:03:33 +0300	[thread overview]
Message-ID: <20200617220335.836265-5-gorcunov@gmail.com> (raw)
In-Reply-To: <20200617220335.836265-1-gorcunov@gmail.com>

Similar to dirname there is no need for +1 byte.
Same time make sure xlog_open never end up without
trailing zero.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 src/box/xlog.c | 6 ++++--
 src/box/xlog.h | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/box/xlog.c b/src/box/xlog.c
index 8b2818326..1685a4cf7 100644
--- a/src/box/xlog.c
+++ b/src/box/xlog.c
@@ -822,7 +822,7 @@ xlog_create(struct xlog *xlog, const char *name, int flags,
 
 	xlog->meta = *meta;
 	xlog->is_inprogress = true;
-	snprintf(xlog->filename, PATH_MAX, "%s%s", name, inprogress_suffix);
+	snprintf(xlog->filename, sizeof(xlog->filename), "%s%s", name, inprogress_suffix);
 
 	flags |= O_RDWR | O_CREAT | O_EXCL;
 
@@ -881,7 +881,9 @@ xlog_open(struct xlog *xlog, const char *name, const struct xlog_opts *opts)
 	if (xlog_init(xlog, opts) != 0)
 		goto err;
 
-	strncpy(xlog->filename, name, PATH_MAX);
+	strncpy(xlog->filename, name, sizeof(xlog->filename));
+	xlog->filename[sizeof(xlog->filename)-1] = '\0';
+
 	xlog->fd = open(xlog->filename, O_RDWR);
 	if (xlog->fd < 0) {
 		say_syserror("open, [%s]", name);
diff --git a/src/box/xlog.h b/src/box/xlog.h
index 329d78c77..9ffce598b 100644
--- a/src/box/xlog.h
+++ b/src/box/xlog.h
@@ -352,7 +352,7 @@ struct xlog {
 	 */
 	int64_t tx_rows;
 	/** Log file name. */
-	char filename[PATH_MAX + 1];
+	char filename[PATH_MAX];
 	/** Whether this file has .inprogress suffix. */
 	bool is_inprogress;
 	/*
-- 
2.26.2

  parent reply	other threads:[~2020-06-17 22:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-17 22:03 [Tarantool-patches] [PATCH 0/6] xlog: cleanup patches Cyrill Gorcunov
2020-06-17 22:03 ` [Tarantool-patches] [PATCH 1/6] box: drop inline from box_cfg_xc Cyrill Gorcunov
2020-06-17 22:03 ` [Tarantool-patches] [PATCH 2/6] xlog: xlog_cursor -- eliminate redundant pad in the structure Cyrill Gorcunov
2020-06-17 22:03 ` [Tarantool-patches] [PATCH 3/6] xlog: xdir -- use PATH_MAX for dirname Cyrill Gorcunov
2020-06-17 22:03 ` Cyrill Gorcunov [this message]
2020-06-18 23:14   ` [Tarantool-patches] [PATCH 4/6] xlog: use PATH_MAX for filename Vladislav Shpilevoy
2020-06-19  7:19     ` Cyrill Gorcunov
2020-06-17 22:03 ` [Tarantool-patches] [PATCH 5/6] xlog: xlog_cursor -- use sizeof with snprintf for safety Cyrill Gorcunov
2020-06-17 22:03 ` [Tarantool-patches] [PATCH 6/6] xlog: xdir_format_filename -- use PATH_MAX Cyrill Gorcunov
2020-06-19 23:17 ` [Tarantool-patches] [PATCH 0/6] xlog: cleanup patches Vladislav Shpilevoy
2020-06-22  7:43 ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200617220335.836265-5-gorcunov@gmail.com \
    --to=gorcunov@gmail.com \
    --cc=alexander.turenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 4/6] xlog: use PATH_MAX for filename' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox