diff options
author | Brennan Ashton <bashton@brennanashton.com> | 2019-10-29 23:09:43 -0700 |
---|---|---|
committer | Marcus Müller <mmueller@gnuradio.org> | 2019-11-01 14:44:45 +0100 |
commit | a75f0c40fe0912535fe102792f27c13d01df8e3e (patch) | |
tree | d045ac2056eeb94aa2cf4f2502b370057684ce0c /gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc | |
parent | b1c588d78571c58b7e9953f4b841f8546ff9da06 (diff) |
runtime: Purge snprintf
We are writting cpp for these operations we should be using std:string
and boost:format. This also cleans up some compiler warnings about
possible string truncation.
Signed-off-by: Brennan Ashton <bashton@brennanashton.com>
Also, removing the `HAVE_SNPRINT` check around the now snprintf-free
handling
Signed-off-by: Marcus Müller <mmueller@gnuradio.org>
Diffstat (limited to 'gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc')
-rw-r--r-- | gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc b/gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc index ec5f320ab1..f6c1777013 100644 --- a/gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc +++ b/gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc @@ -41,6 +41,7 @@ #include <fcntl.h> #include <stdio.h> #include <string.h> +#include <boost/format.hpp> namespace gr { @@ -58,34 +59,33 @@ vmcircbuf_mmap_tmpfile::vmcircbuf_mmap_tmpfile(int size) : gr::vmcircbuf(size) } int seg_fd = -1; - char seg_name[1024]; + std::string seg_name; static int s_seg_counter = 0; // open a temporary file that we'll map in a bit later while (1) { - snprintf(seg_name, - sizeof(seg_name), - "%s/gnuradio-%d-%d-XXXXXX", - gr::tmp_path(), - getpid(), - s_seg_counter); + seg_name = str(boost::format( + "%s/gnuradio-%d-%d-XXXXXX") % + gr::tmp_path() % + getpid() % + s_seg_counter); s_seg_counter++; - seg_fd = open(seg_name, O_RDWR | O_CREAT | O_EXCL, 0600); + seg_fd = open(seg_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600); if (seg_fd == -1) { if (errno == EEXIST) // File already exists (shouldn't happen). Try again continue; - char msg[1024]; - snprintf(msg, sizeof(msg), "gr::vmcircbuf_mmap_tmpfile: open [%s]", seg_name); - perror(msg); + static std::string msg = + str(boost::format("gr::vmcircbuf_mmap_tmpfile: open [%s]") % seg_name); + perror(msg.c_str()); throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile"); } break; } - if (unlink(seg_name) == -1) { + if (unlink(seg_name.c_str()) == -1) { perror("gr::vmcircbuf_mmap_tmpfile: unlink"); throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile"); } |