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