From 26137977cdc16645ea5a21ffe117d9607fce557c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 16 Nov 2016 16:30:46 -0800 Subject: [PATCH] Fix crash when return value pointer is null --- .../api/atom_api_system_preferences_mac.mm | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/atom/browser/api/atom_api_system_preferences_mac.mm b/atom/browser/api/atom_api_system_preferences_mac.mm index aee0b4631613..edb875c0b243 100644 --- a/atom/browser/api/atom_api_system_preferences_mac.mm +++ b/atom/browser/api/atom_api_system_preferences_mac.mm @@ -28,17 +28,17 @@ std::map g_id_map; } // namespace -void SystemPreferences::PostNotification(const std::string& name, +void SystemPreferences::PostNotification(const std::string& name, const base::DictionaryValue& user_info) { DoPostNotification(name, user_info, false); } -void SystemPreferences::PostLocalNotification(const std::string& name, +void SystemPreferences::PostLocalNotification(const std::string& name, const base::DictionaryValue& user_info) { DoPostNotification(name, user_info, true); } -void SystemPreferences::DoPostNotification(const std::string& name, +void SystemPreferences::DoPostNotification(const std::string& name, const base::DictionaryValue& user_info, bool is_local) { NSNotificationCenter* center = is_local ? [NSNotificationCenter defaultCenter] : @@ -128,11 +128,17 @@ v8::Local SystemPreferences::GetUserDefault( return mate::ConvertToV8(isolate(), net::GURLWithNSURL([defaults URLForKey:key])); } else if (type == "array") { - return mate::ConvertToV8(isolate(), - *NSArrayToListValue([defaults arrayForKey:key])); + std::unique_ptr list = + NSArrayToListValue([defaults arrayForKey:key]); + if (list == nullptr) + list.reset(new base::ListValue()); + return mate::ConvertToV8(isolate(), *list); } else if (type == "dictionary") { - return mate::ConvertToV8(isolate(), - *NSDictionaryToDictionaryValue([defaults dictionaryForKey:key])); + std::unique_ptr dictionary = + NSDictionaryToDictionaryValue([defaults dictionaryForKey:key]); + if (dictionary == nullptr) + dictionary.reset(new base::DictionaryValue()); + return mate::ConvertToV8(isolate(), *dictionary); } else { return v8::Undefined(isolate()); }