[3/3] cosmetic: gtp.c: clarify strncpy nul term

Submitted by Neels Hofmeyr on Sept. 15, 2016, 1:06 p.m.

Details

Message ID 1473944800-6054-3-git-send-email-nhofmeyr@sysmocom.de
State New
Series "Series without cover letter"
Headers show

Commit Message

Neels Hofmeyr Sept. 15, 2016, 1:06 p.m.
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(-)

Patch hide | download patch | download mbox

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);