From 867ce7f7985175e77f679141b698c474bd52b4c1 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Mon, 18 May 2015 18:40:47 -0700 Subject: Fix cache path initialization and set. Add null terminator to strings Return nullptr if string is not set bug 20894664 Change-Id: I33f5d84d56f6299558f5d8713694e40afc82dd20 --- rsContext.cpp | 18 ++++++++++++++++++ rsContext.h | 17 ++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/rsContext.cpp b/rsContext.cpp index 29b4036f..fba06cd9 100644 --- a/rsContext.cpp +++ b/rsContext.cpp @@ -459,8 +459,26 @@ Context::Context() { mContextType = RS_CONTEXT_TYPE_NORMAL; mSynchronous = false; mFatalErrorOccured = false; + + memset(mCacheDir, 0, sizeof(mCacheDir)); +#ifdef RS_COMPATIBILITY_LIB + memset(nativeLibDir, 0, sizeof(nativeLibDir)); +#endif } +void Context::setCacheDir(const char * cacheDir_arg, uint32_t length) { + if (!hasSetCacheDir) { + if (length <= PATH_MAX) { + memcpy(mCacheDir, cacheDir_arg, length); + mCacheDir[length] = 0; + hasSetCacheDir = true; + } else { + setError(RS_ERROR_BAD_VALUE, "Invalid path"); + } + } +} + + Context * Context::createContext(Device *dev, const RsSurfaceConfig *sc, RsContextType ct, uint32_t flags) { Context * rsc = new Context(); diff --git a/rsContext.h b/rsContext.h index 6cb0ed76..c6b70797 100644 --- a/rsContext.h +++ b/rsContext.h @@ -258,6 +258,7 @@ public: if (!hasSetNativeLibDir) { if (length <= PATH_MAX) { memcpy(nativeLibDir, libDir, length); + nativeLibDir[length] = 0; hasSetNativeLibDir = true; } else { setError(RS_ERROR_BAD_VALUE, "Invalid path"); @@ -269,18 +270,12 @@ public: } #endif - void setCacheDir(const char * cacheDir_arg, uint32_t length) { - if (!hasSetCacheDir) { - if (length <= PATH_MAX) { - memcpy(mCacheDir, cacheDir_arg, length); - hasSetCacheDir = true; - } else { - setError(RS_ERROR_BAD_VALUE, "Invalid path"); - } - } - } + void setCacheDir(const char * cacheDir_arg, uint32_t length); const char * getCacheDir() { - return mCacheDir; + if (hasSetCacheDir) { + return mCacheDir; + } + return nullptr; } // Returns the actual loaded driver's name (like "libRSDriver.so"). -- cgit v1.2.3