discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] bug in gri_fft.cc


From: Marek Czerski
Subject: [Discuss-gnuradio] bug in gri_fft.cc
Date: Thu, 27 Jun 2013 10:43:29 +0200

Hi all,

I found a bug in gnuradio-core/src/lib/general/gri_fft.cc, in function:
static const char * wisdom_filename ()

It returns pointer to char string from temporary object created by call to path.string(). Obviously, this pointer is pointing to garbage after exit from wisdom_filename() function.

I propose something like this:

 gnuradio-core/src/lib/general/gri_fft.cc | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/gnuradio-core/src/lib/general/gri_fft.cc b/gnuradio-core/src/lib/general/gri_fft.cc
index 68e7e69..906279b 100644
--- a/gnuradio-core/src/lib/general/gri_fft.cc
+++ b/gnuradio-core/src/lib/general/gri_fft.cc
@@ -73,18 +73,19 @@ gri_fft_planner::mutex()
   return s_planning_mutex;
 }
 
-static const char *
+static std::string
 wisdom_filename ()
 {
   static fs::path path;
   path = fs::path(gr_appdata_path()) / ".gr_fftw_wisdom";
-  return path.string().c_str();
+  return path.string();
 }
 
 static void
 gri_fftw_import_wisdom ()
 {
-  const char *filename = wisdom_filename ();
+  const std::string & s = wisdom_filename ();
+  const char *filename = s.c_str ();
   FILE *fp = fopen (filename, "r");
   if (fp != 0){
     int r = fftwf_import_wisdom_from_file (fp);
@@ -114,7 +115,8 @@ gri_fftw_config_threading (int nthreads)
 static void
 gri_fftw_export_wisdom ()
 {
-  const char *filename = wisdom_filename ();
+  const std::string & s = wisdom_filename ();
+  const char *filename = s.c_str ();
   FILE *fp = fopen (filename, "w");
   if (fp != 0){
     fftwf_export_wisdom_to_file (fp);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]