From ed22f8e219eb0fd5ab796eefa3cef4f83673ab8b Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sat, 6 Jan 2018 01:45:16 +0000 Subject: [PATCH] util.c: use x*sprintf instead of s*printf * util.c: Include "xstring.h". (sprinttime_ex): Replace snprintf with xsnprintf. (getfdproto): Replace sprintf with xsprintf. --- util.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/util.c b/util.c index 05c9fb80..0b4c5b7a 100644 --- a/util.c +++ b/util.c @@ -40,6 +40,7 @@ # include #endif #include +#include "xstring.h" int tv_nz(const struct timeval *a) @@ -344,15 +345,9 @@ sprinttime_ex(const long long sec, const unsigned long long part_sec, if (!pos) return NULL; - if (part_sec > 0) { - int ret = snprintf(buf + pos, sizeof(buf) - pos, ".%0*llu", - width, part_sec); - - if (ret < 0 || (size_t) ret >= sizeof(buf) - pos) - return NULL; - - pos += ret; - } + if (part_sec > 0) + pos += xsnprintf(buf + pos, sizeof(buf) - pos, ".%0*llu", + width, part_sec); return strftime(buf + pos, sizeof(buf) - pos, "%z", tmp) ? buf : NULL; } @@ -387,7 +382,7 @@ getfdproto(struct tcb *tcp, int fd) if (fd < 0) return SOCK_PROTO_UNKNOWN; - sprintf(path, "/proc/%u/fd/%u", tcp->pid, fd); + xsprintf(path, "/proc/%u/fd/%u", tcp->pid, fd); r = getxattr(path, "system.sockprotoname", buf, bufsize - 1); if (r <= 0) return SOCK_PROTO_UNKNOWN; -- 2.40.0