From be9b1a188737c3cf5b08b875f2e4153ee5a47446 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 3 Mar 2021 10:47:41 +0100 Subject: [PATCH] tweaks: avoid a warning on newer compilers, by writing an extra byte When the version number is a trio, the version string will occupy ten bytes and the terminating NUL byte would not be written (which was not a problem as byte 12 of the lock data is zero anyway). But it's better to not have the compiler complain, so allow writing the terminating NUL byte outside of the ten bytes reserved for the version string. --- src/files.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/files.c b/src/files.c index bc876cb1..45f6bbd8 100644 --- a/src/files.c +++ b/src/files.c @@ -200,7 +200,8 @@ bool write_lockfile(const char *lockfilename, const char *filename, bool modifie * some byte-order-checking numbers (bytes 1008-1022). */ lockdata[0] = 0x62; lockdata[1] = 0x30; - snprintf(&lockdata[2], 10, "nano %s", VERSION); + /* It's fine to overwrite byte 12 with the \0 as it is 0x00 anyway. */ + snprintf(&lockdata[2], 11, "nano %s", VERSION); lockdata[24] = mypid % 256; lockdata[25] = (mypid / 256) % 256; lockdata[26] = (mypid / (256 * 256)) % 256;