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

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/osmocom-net-gprs@lists.osmocom.org/.

Neels Hofmeyr nhofmeyr at sysmocom.de
Thu Sep 15 13:06:40 UTC 2016


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




More information about the osmocom-net-gprs mailing list