diff --git a/lib/.gitignore b/lib/.gitignore index db09928b..7f9045d4 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -313,6 +313,7 @@ /stdlib.h /stdlib.in.h /stpcpy.c +/stpncpy.c /strchrnul.c /strchrnul.valgrind /strdup.c diff --git a/m4/.gitignore b/m4/.gitignore index 5389544d..cca78f48 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -175,6 +175,7 @@ /stdio_h.m4 /stdlib_h.m4 /stpcpy.m4 +/stpncpy.m4 /strchrnul.m4 /strdup.m4 /strerror.m4 diff --git a/src/glyphs.c b/src/glyphs.c index 0c0e9fc2..b69659d8 100644 --- a/src/glyphs.c +++ b/src/glyphs.c @@ -63,8 +63,8 @@ static long on_success (const char *buf, size_t buflen, void *callback_arg) { callback_arg_t *arg = (callback_arg_t *) callback_arg; - assert (buflen < sizeof arg->buf); - strncpy (arg->buf, buf, buflen); + assert (buflen + 1 < sizeof arg->buf); + *stpncpy (arg->buf, buf, buflen) = '\0'; return 1; } @@ -73,7 +73,7 @@ on_failure (unsigned code MAYBE_UNUSED, const char *msg MAYBE_UNUSED, void *callback_arg) { callback_arg_t *arg = (callback_arg_t *) callback_arg; - assert (strlen (arg->fallback) < sizeof arg->buf); + assert (strlen (arg->fallback) + 1 < sizeof arg->buf); strcpy (arg->buf, arg->fallback); return 0; }