mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
NSBundle.m: objc_executable_location(): A cast was obsuring a misuse of fileSystemRepresentation
NSFileManager.m: isExecutableFileAtPath: Added a comment NSPropertyList.m: propertyListFromData:mutabilityOption:format:errorDescription: Don't call memcmp if the data is smaller than 8 bytes. objc-load.m: mingw unicode win32-load.h: mingw unicode NSUserDefaultsWin32.m: Write defaults to registry as unicode strings, read in either unicode(REG_SZ) or ascii(REG_BINARY). git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22782 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
afcdd8bca1
commit
7d20644264
6 changed files with 71 additions and 14 deletions
|
@ -255,10 +255,14 @@ static NSString *ExecutablePath()
|
|||
|
||||
/* This function is provided for objc-load.c, although I'm not sure it
|
||||
really needs it (So far only needed if using GNU dld library) */
|
||||
#ifdef __MINGW32__
|
||||
const unichar *
|
||||
#else
|
||||
const char *
|
||||
#endif
|
||||
objc_executable_location (void)
|
||||
{
|
||||
return (const char*)[[ExecutablePath() stringByDeletingLastPathComponent]
|
||||
return [[ExecutablePath() stringByDeletingLastPathComponent]
|
||||
fileSystemRepresentation];
|
||||
}
|
||||
|
||||
|
|
|
@ -1491,6 +1491,7 @@ static NSStringEncoding defaultEncoding;
|
|||
{
|
||||
return NO;
|
||||
}
|
||||
// TODO: Actually should check all extensions in env var PATHEXT
|
||||
if ([[[path pathExtension] lowercaseString] isEqualToString: @"exe"])
|
||||
{
|
||||
return YES;
|
||||
|
|
|
@ -2255,7 +2255,7 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml,
|
|||
{
|
||||
bytes = [data bytes];
|
||||
length = [data length];
|
||||
if (length > 0 && memcmp(bytes, "bplist00", 8) == 0)
|
||||
if (length >= 8 && memcmp(bytes, "bplist00", 8) == 0)
|
||||
{
|
||||
format = NSPropertyListBinaryFormat_v1_0;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,11 @@
|
|||
#include "dynamic-load.h"
|
||||
|
||||
/* Declaration from NSBundle.m */
|
||||
#ifdef __MINGW32__
|
||||
const unichar *objc_executable_location (void);
|
||||
#else
|
||||
const char *objc_executable_location (void);
|
||||
#endif
|
||||
|
||||
/* dynamic_loaded is YES if the dynamic loader was sucessfully initialized. */
|
||||
static BOOL dynamic_loaded;
|
||||
|
@ -101,7 +105,11 @@ objc_check_undefineds(FILE *errorStream)
|
|||
static int
|
||||
objc_initialize_loading(FILE *errorStream)
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
const unichar *path;
|
||||
#else
|
||||
const char *path;
|
||||
#endif
|
||||
|
||||
dynamic_loaded = NO;
|
||||
path = objc_executable_location();
|
||||
|
|
|
@ -34,7 +34,7 @@ typedef void* dl_symbol_t;
|
|||
if no initialization needed.
|
||||
*/
|
||||
static int
|
||||
__objc_dynamic_init(const char* exec_path)
|
||||
__objc_dynamic_init(const unichar* exec_path)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -205,7 +205,7 @@ struct NSUserDefaultsWin32_DomainInfo
|
|||
{
|
||||
DWORD i = 0;
|
||||
unichar *name = malloc(200);
|
||||
unsigned char *data = malloc(1000);
|
||||
unichar *data = malloc(1000);
|
||||
DWORD namelenbuf = 100, datalenbuf = 1000;
|
||||
DWORD type;
|
||||
|
||||
|
@ -219,7 +219,7 @@ struct NSUserDefaultsWin32_DomainInfo
|
|||
&namelen,
|
||||
NULL,
|
||||
&type,
|
||||
data,
|
||||
(void*)data,
|
||||
&datalen);
|
||||
if (rc == ERROR_SUCCESS)
|
||||
{
|
||||
|
@ -228,12 +228,31 @@ struct NSUserDefaultsWin32_DomainInfo
|
|||
id v;
|
||||
NSString *k;
|
||||
|
||||
v = [NSString stringWithCString: data
|
||||
switch (type) {
|
||||
case REG_SZ: {
|
||||
int datacharlen = datalen / 2;
|
||||
if (datacharlen > 0 && data[datacharlen-1] == 0)
|
||||
datacharlen--;
|
||||
|
||||
v = [NSString stringWithCharacters:data length:datacharlen];
|
||||
}
|
||||
break;
|
||||
case REG_BINARY: {
|
||||
v = [NSString stringWithCString: (char*)data
|
||||
encoding: NSASCIIStringEncoding];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
NSLog(@"Bad registry type %d for '%S'", type, name);
|
||||
v = 0;
|
||||
}
|
||||
v = [v propertyList];
|
||||
if (v)
|
||||
{
|
||||
k = [NSString stringWithCharacters: name length: namelen];
|
||||
[domainDict setObject: v forKey: k];
|
||||
}
|
||||
}
|
||||
NS_HANDLER
|
||||
NSLog(@"Bad registry value for '%S'", name);
|
||||
NS_ENDHANDLER
|
||||
|
@ -271,7 +290,7 @@ struct NSUserDefaultsWin32_DomainInfo
|
|||
{
|
||||
DWORD i = 0;
|
||||
unichar *name = malloc(200);
|
||||
unsigned char *data = malloc(1000);
|
||||
unichar *data = malloc(1000);
|
||||
DWORD namelenbuf = 100, datalenbuf = 1000;
|
||||
DWORD type;
|
||||
|
||||
|
@ -279,13 +298,19 @@ struct NSUserDefaultsWin32_DomainInfo
|
|||
{
|
||||
DWORD namelen = namelenbuf, datalen = datalenbuf;
|
||||
|
||||
// RegEnumValueW returns the data as a wide string
|
||||
// but returns the length in bytes.
|
||||
// To add insult to injury, datalen includes the terminating
|
||||
// NULL character, unless there isn't enough room, in which
|
||||
// case it doesn't.
|
||||
|
||||
rc = RegEnumValueW(dinfo->userKey,
|
||||
i,
|
||||
name,
|
||||
&namelen,
|
||||
NULL,
|
||||
&type,
|
||||
data,
|
||||
(void*)data,
|
||||
&datalen);
|
||||
if (rc == ERROR_SUCCESS)
|
||||
{
|
||||
|
@ -294,12 +319,31 @@ struct NSUserDefaultsWin32_DomainInfo
|
|||
id v;
|
||||
NSString *k;
|
||||
|
||||
v = [NSString stringWithCString: data
|
||||
switch (type) {
|
||||
case REG_SZ: {
|
||||
int datacharlen = datalen / 2;
|
||||
if (datacharlen > 0 && data[datacharlen-1] == 0)
|
||||
datacharlen--;
|
||||
|
||||
v = [NSString stringWithCharacters:data length:datacharlen];
|
||||
}
|
||||
break;
|
||||
case REG_BINARY: {
|
||||
v = [NSString stringWithCString: (char*)data
|
||||
encoding: NSASCIIStringEncoding];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
NSLog(@"Bad registry type %d for '%S'", type, name);
|
||||
v = 0;
|
||||
}
|
||||
v = [v propertyList];
|
||||
if (v)
|
||||
{
|
||||
k = [NSString stringWithCharacters: name length: namelen];
|
||||
[domainDict setObject: v forKey: k];
|
||||
}
|
||||
}
|
||||
NS_HANDLER
|
||||
NSLog(@"Bad registry value for '%S'", name);
|
||||
NS_ENDHANDLER
|
||||
|
@ -523,16 +567,16 @@ struct NSUserDefaultsWin32_DomainInfo
|
|||
if (oldvalue == nil || [value isEqual: oldvalue] == NO)
|
||||
{
|
||||
NSString *result = nil;
|
||||
const unsigned char *ptr;
|
||||
const unichar *ptr;
|
||||
|
||||
GSPropertyListMake(value, nil, NO, NO, 0, &result);
|
||||
ptr = [result cStringUsingEncoding: NSASCIIStringEncoding];
|
||||
ptr = UNISTR(result);
|
||||
rc = RegSetValueExW(dinfo->userKey,
|
||||
UNISTR(valName),
|
||||
0,
|
||||
REG_BINARY,
|
||||
ptr,
|
||||
strlen(ptr) + 1);
|
||||
REG_SZ,
|
||||
(void*)ptr,
|
||||
2*(wcslen(ptr) + 1));
|
||||
if (rc != ERROR_SUCCESS)
|
||||
{
|
||||
NSLog(@"Failed to insert HKEY_CURRENT_USER\\%@\\%@ (%x)",
|
||||
|
|
Loading…
Reference in a new issue