diff options
author | Quentin Young <qlyoung@cumulusnetworks.com> | 2020-04-20 20:12:38 +0200 |
---|---|---|
committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2020-04-21 01:14:33 +0200 |
commit | 772270f3b6a37a2dd9432541cce436e9b45bb6b9 (patch) | |
tree | fc7f717a60d056b0300fcf43373a1fff30b94b13 /lib/csv.c | |
parent | tools: add more macros to cocci.h (diff) | |
download | frr-772270f3b6a37a2dd9432541cce436e9b45bb6b9.tar.xz frr-772270f3b6a37a2dd9432541cce436e9b45bb6b9.zip |
*: sprintf -> snprintf
Replace sprintf with snprintf where straightforward to do so.
- sprintf's into local scope buffers of known size are replaced with the
equivalent snprintf call
- snprintf's into local scope buffers of known size that use the buffer
size expression now use sizeof(buffer)
- sprintf(buf + strlen(buf), ...) replaced with snprintf() into temp
buffer followed by strlcat
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/csv.c')
-rw-r--r-- | lib/csv.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -640,7 +640,7 @@ static int get_memory_usage(pid_t pid) char buf[4096], status_child[BUFSIZ]; char *vm; - sprintf(status_child, "/proc/%d/status", pid); + snprintf(status_child, sizeof(status_child), "/proc/%d/status", pid); if ((fd = open(status_child, O_RDONLY)) < 0) return -1; @@ -672,8 +672,8 @@ int main() log_verbose("Mem: %d\n", get_memory_usage(getpid())); csv_init(&csv, buf, 256); - sprintf(hdr1, "%4d", 0); - sprintf(hdr2, "%4d", 1); + snprintf(hdr1, sizeof(hdr1), "%4d", 0); + snprintf(hdr2, sizeof(hdr2), "%4d", 1); log_verbose("(%zu/%zu/%d/%d)\n", strlen(hdr1), strlen(hdr2), atoi(hdr1), atoi(hdr2)); rec = csv_encode(&csv, 2, hdr1, hdr2); @@ -685,8 +685,8 @@ int main() } csv_encode(&csv, 2, "pdfadfadfadsadsaddfdfdsfdsd", "35444554545454545"); log_verbose("%s\n", buf); - sprintf(hdr1, "%4d", csv.csv_len); - sprintf(hdr2, "%4d", 1); + snprintf(hdr1, sizeof(hdr1), "%4d", csv.csv_len); + snprintf(hdr2, sizeof(hdr2), "%4d", 1); log_verbose("(%zu/%zu/%d/%d)\n", strlen(hdr1), strlen(hdr2), atoi(hdr1), atoi(hdr2)); rec = csv_encode_record(&csv, rec, 2, hdr1, hdr2); |