Commit f7dfe5d6 authored by Jan Djärv's avatar Jan Djärv

Don't crash on bad user input.

* nsfns.m (ns_get_defaults_value): New function.
(Fns_get_resource, x_get_string_resource): Call ns_get_defaults_value.

* nsterm.h (ns_get_defaults_value): Declare.

* nsterm.m (ns_default): Call ns_get_defaults_value.

Fixes: debbugs:10103
parent 2ce25263
2011-12-10 Jan Djärv <jan.h.d@swipnet.se>
* nsfns.m (ns_get_defaults_value): New function (Bug#10103).
(Fns_get_resource, x_get_string_resource): Call ns_get_defaults_value.
* nsterm.h (ns_get_defaults_value): Declare.
* nsterm.m (ns_default): Call ns_get_defaults_value.
2011-12-09 Eli Zaretskii <eliz@gnu.org>
* xdisp.c (try_scrolling): Don't set scroll_down_p if dy is zero.
......
......@@ -1546,6 +1546,17 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
return ret ? fname : Qnil;
}
const char *
ns_get_defaults_value (const char *key)
{
NSObject *obj = [[NSUserDefaults standardUserDefaults]
objectForKey: [NSString stringWithUTF8String: key]];
if (!obj) return NULL;
return [[NSString stringWithFormat: @"%@", obj] UTF8String];
}
DEFUN ("ns-get-resource", Fns_get_resource, Sns_get_resource, 2, 2, 0,
doc: /* Return the value of the property NAME of OWNER from the defaults database.
......@@ -1560,9 +1571,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side
CHECK_STRING (name);
/*fprintf (stderr, "ns-get-resource checking resource '%s'\n", SDATA (name)); */
value =[[[NSUserDefaults standardUserDefaults]
objectForKey: [NSString stringWithUTF8String: SDATA (name)]]
UTF8String];
value = ns_get_defaults_value (SDATA (name));
if (value)
return build_string (value);
......@@ -2217,8 +2226,7 @@ and GNUstep implementations ("distributor-specific release
/* --quick was passed, so this is a no-op. */
return NULL;
res = [[[NSUserDefaults standardUserDefaults] objectForKey:
[NSString stringWithUTF8String: toCheck]] UTF8String];
res = ns_get_defaults_value (toCheck);
return !res ? NULL :
(!strncasecmp (res, "YES", 3) ? "true" :
(!strncasecmp (res, "NO", 2) ? "false" : res));
......
......@@ -760,6 +760,7 @@ extern void ns_release_object (void *obj);
extern void ns_retain_object (void *obj);
extern void *ns_alloc_autorelease_pool ();
extern void ns_release_autorelease_pool ();
extern const char *ns_get_defaults_value ();
/* in nsmenu */
extern void update_frame_tool_bar (FRAME_PTR f);
......
......@@ -3824,11 +3824,9 @@ Convert modifier code (see lisp.h) to lisp symbol
Check a parameter value in user's preferences
-------------------------------------------------------------------------- */
{
const char *value;
const char *value = ns_get_defaults_value (parameter);
if ( (value =[[[NSUserDefaults standardUserDefaults]
stringForKey: [NSString stringWithUTF8String: parameter]]
UTF8String]) )
if (value)
{
double f;
char *pos;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment