From patchwork Thu Sep 15 13:06:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [3/3] cosmetic: gtp.c: clarify strncpy nul term From: Neels Hofmeyr X-Patchwork-Id: 237859 Message-Id: <1473944800-6054-3-git-send-email-nhofmeyr@sysmocom.de> To: osmocom-net-gprs@lists.osmocom.org Date: Thu, 15 Sep 2016 15:06:40 +0200 Rather nul-terminate string buffer after writing bytes. This is only cosmetic since 'NAMESIZE - 1' is passed to the strn* functions. This ordering shows the intention more clearly. Also put the comment on its own line and explain in more detail. --- gtp/gtp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gtp/gtp.c b/gtp/gtp.c index cdff238..c974b7b 100644 --- a/gtp/gtp.c +++ b/gtp/gtp.c @@ -648,9 +648,10 @@ static void log_restart(struct gsn_t *gsn) int counter = 0; char filename[NAMESIZE]; - filename[NAMESIZE - 1] = 0; /* No null term. guarantee by strncpy */ strncpy(filename, gsn->statedir, NAMESIZE - 1); strncat(filename, "/" RESTART_FILE, NAMESIZE - 1 - strlen(filename)); + /* guarantee nul term, strncpy might omit if too long */ + filename[NAMESIZE - 1] = 0; i = umask(022);