Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(870)

Unified Diff: src/utils/SkRTConf.cpp

Issue 26373008: Fix a bug which caused crash in SkRTConfig whith string values in environment variables (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: simplify Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkRTConf.cpp
diff --git a/src/utils/SkRTConf.cpp b/src/utils/SkRTConf.cpp
index 6fcc318d25312ad6942f675f45fd7899b0cc2997..9a70eb6b78165b2a07050b38e491852b05f50aea 100644
--- a/src/utils/SkRTConf.cpp
+++ b/src/utils/SkRTConf.cpp
@@ -213,12 +213,11 @@ static inline void str_replace(char *s, char search, char replace) {
}
template<typename T> bool SkRTConfRegistry::parse(const char *name, T* value) {
- SkString *str = NULL;
- SkString tmp;
+ const char *str = NULL;
for (int i = fConfigFileKeys.count() - 1 ; i >= 0; i--) {
if (fConfigFileKeys[i]->equals(name)) {
- str = fConfigFileValues[i];
+ str = fConfigFileValues[i]->c_str();
break;
}
}
@@ -228,24 +227,15 @@ template<typename T> bool SkRTConfRegistry::parse(const char *name, T* value) {
const char *environment_value = getenv(environment_variable.c_str());
if (environment_value) {
- if (NULL == str) {
- str = &tmp;
- }
- str->set(environment_value);
+ str = environment_value;
} else {
// apparently my shell doesn't let me have environment variables that
// have periods in them, so also let the user substitute underscores.
- SkString underscore_environment_variable("skia_");
- char *underscore_name = SkStrDup(name);
- str_replace(underscore_name,'.','_');
- underscore_environment_variable.append(underscore_name);
- sk_free(underscore_name);
- environment_value = getenv(underscore_environment_variable.c_str());
+ SkAutoTMalloc<char> underscore_name(SkStrDup(environment_variable.c_str()));
+ str_replace(underscore_name.get(),'.','_');
+ environment_value = getenv(underscore_name.get());
if (environment_value) {
- if (NULL == str) {
- str = &tmp;
- }
- str->set(environment_value);
+ str = environment_value;
}
}
@@ -254,11 +244,12 @@ template<typename T> bool SkRTConfRegistry::parse(const char *name, T* value) {
}
bool success;
- T new_value = doParse<T>(str->c_str(),&success);
+ T new_value = doParse<T>(str, &success);
if (success) {
*value = new_value;
} else {
- SkDebugf("WARNING: Couldn't parse value \'%s\' for variable \'%s\'\n", str->c_str(), name);
+ SkDebugf("WARNING: Couldn't parse value \'%s\' for variable \'%s\'\n",
+ str, name);
}
return success;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698