[Mesa-dev] [PATCH 1/1] clover: Remove compat::string::c_str

Jan Vesely jan.vesely at rutgers.edu
Thu Sep 4 09:35:20 PDT 2014


It's unsafe as compat::string is not null terminated.
Fixes garbage log on successful build.

Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---

It's obviously not needed in program::build, but I'm not sure
if runtime_error solution is the best one.


 src/gallium/state_trackers/clover/core/program.cpp | 4 ++--
 src/gallium/state_trackers/clover/util/compat.cpp  | 2 +-
 src/gallium/state_trackers/clover/util/compat.hpp  | 5 -----
 3 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/src/gallium/state_trackers/clover/core/program.cpp b/src/gallium/state_trackers/clover/core/program.cpp
index 30a1f0e..3e9abec 100644
--- a/src/gallium/state_trackers/clover/core/program.cpp
+++ b/src/gallium/state_trackers/clover/core/program.cpp
@@ -61,9 +61,9 @@ program::build(const ref_vector<device> &devs, const char *opts) {
                                                 dev.ir_target(), build_opts(dev),
                                                 log));
             _binaries.insert({ &dev, module });
-            _logs.insert({ &dev, std::string(log.c_str()) });
+            _logs.insert({ &dev, std::string(log) });
          } catch (const build_error &) {
-            _logs.insert({ &dev, std::string(log.c_str()) });
+            _logs.insert({ &dev, std::string(log) });
             throw;
          }
       }
diff --git a/src/gallium/state_trackers/clover/util/compat.cpp b/src/gallium/state_trackers/clover/util/compat.cpp
index 80d5b3e..afba92e 100644
--- a/src/gallium/state_trackers/clover/util/compat.cpp
+++ b/src/gallium/state_trackers/clover/util/compat.cpp
@@ -34,5 +34,5 @@ exception::what() const {
 
 const char *
 runtime_error::what() const {
-   return _what.c_str();
+   return ((std::string)_what).c_str();
 }
diff --git a/src/gallium/state_trackers/clover/util/compat.hpp b/src/gallium/state_trackers/clover/util/compat.hpp
index 50e1c7d..b3668c5 100644
--- a/src/gallium/state_trackers/clover/util/compat.hpp
+++ b/src/gallium/state_trackers/clover/util/compat.hpp
@@ -280,11 +280,6 @@ namespace clover {
          }
 
          const char *
-         c_str() const {
-            return begin();
-         }
-
-         const char *
          find(const string &s) const {
             for (size_t i = 0; i + s.size() < size(); ++i) {
                if (!std::memcmp(begin() + i, s.begin(), s.size()))
-- 
1.9.3



More information about the mesa-dev mailing list