diff options
| author | Thomas Holder <thomas@thomas-holder.de> | 2018-09-12 13:05:49 +0000 |
|---|---|---|
| committer | Thomas Holder <thomas@thomas-holder.de> | 2018-09-12 13:05:49 +0000 |
| commit | 38a3495fee359a5d24c56edf0185797806bbf489 (patch) | |
| tree | f3a9ba5bf7260751c6986f293c2855c7e080caaa | |
| parent | Support smooth scrolling (part 2) (diff) | |
| download | inkscape-38a3495fee359a5d24c56edf0185797806bbf489.tar.gz inkscape-38a3495fee359a5d24c56edf0185797806bbf489.zip | |
Fix preferences crash
a81d0009 regression
| -rw-r--r-- | src/preferences.cpp | 27 | ||||
| -rw-r--r-- | src/preferences.h | 2 |
2 files changed, 25 insertions, 4 deletions
diff --git a/src/preferences.cpp b/src/preferences.cpp index e05767757..c32d6082d 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -39,6 +39,10 @@ static void migrateDetails( Inkscape::XML::Document *from, Inkscape::XML::Docume static Inkscape::XML::Document *migrateFromDoc = nullptr; +// cachedRawValue prefixes for encoding nullptr +static Glib::ustring const RAWCACHE_CODE_NULL {"N"}; +static Glib::ustring const RAWCACHE_CODE_VALUE {"V"}; + // TODO clean up. Function copied from file.cpp: // what gets passed here is not actually an URI... it is an UTF-8 encoded filename (!) static void file_add_recent(gchar const *uri) @@ -749,7 +753,18 @@ Inkscape::XML::Node *Preferences::_getNode(Glib::ustring const &pref_key, bool c void Preferences::_getRawValue(Glib::ustring const &path, gchar const *&result) { - if (cachedRawValue.find(path)!=cachedRawValue.end()) { result = cachedRawValue.at(path); return; } + // will return empty string if `path` was not in the cache yet + auto& cacheref = cachedRawValue[path]; + + if (!cacheref.empty()) { + if (cacheref == RAWCACHE_CODE_NULL) { + result = nullptr; + } else { + result = cacheref.c_str() + RAWCACHE_CODE_VALUE.length(); + } + return; + } + // create node and attribute keys Glib::ustring node_key, attr_key; _keySplit(path, node_key, attr_key); @@ -766,7 +781,13 @@ void Preferences::_getRawValue(Glib::ustring const &path, gchar const *&result) result = attr; } } - cachedRawValue[path] = result; + + if (!result) { + cacheref = RAWCACHE_CODE_NULL; + } else { + cacheref = RAWCACHE_CODE_VALUE; + cacheref += result; + } } void Preferences::_setRawValue(Glib::ustring const &path, Glib::ustring const &value) @@ -778,7 +799,7 @@ void Preferences::_setRawValue(Glib::ustring const &path, Glib::ustring const &v // set the attribute Inkscape::XML::Node *node = _getNode(node_key, true); node->setAttribute(attr_key.c_str(), value.c_str()); - cachedRawValue[path] = value.c_str(); + cachedRawValue[path] = RAWCACHE_CODE_VALUE + value; } // The _extract* methods are where the actual work is done - they define how preferences are stored diff --git a/src/preferences.h b/src/preferences.h index 27723245a..ac6bf91a1 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -552,7 +552,7 @@ private: ErrorReporter* _errorHandler; ///< Pointer to object reporting errors. bool _writable; ///< Will the preferences be saved at exit? bool _hasError; ///< Indication that some error has occurred; - std::map<Glib::ustring, const gchar*> cachedRawValue; + std::map<Glib::ustring, Glib::ustring> cachedRawValue; /// Wrapper class for XML node observers class PrefNodeObserver; |
