Fixes for problems spotted by Wolfgang

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@40171 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2016-10-24 10:22:43 +00:00
parent 3d9ffaf168
commit 1ab80b3f58
4 changed files with 33 additions and 9 deletions

View file

@ -229,8 +229,10 @@ encodebase64(unsigned char **dstRef,
}
static BOOL
readContentsOfFile(NSString* path, void** buf, off_t* len, NSZone* zone)
readContentsOfFile(NSString *path, void **buf, off_t *len, NSZone *zone)
{
NSFileManager *mgr = [NSFileManager defaultManager];
NSDictionary *att;
#if defined(_WIN32)
const unichar *thePath = 0;
#else
@ -239,7 +241,7 @@ readContentsOfFile(NSString* path, void** buf, off_t* len, NSZone* zone)
FILE *theFile = 0;
void *tmp = 0;
int c;
off_t fileLength;
off_t fileLength;
#if defined(_WIN32)
thePath = (const unichar*)[path fileSystemRepresentation];
@ -252,6 +254,13 @@ readContentsOfFile(NSString* path, void** buf, off_t* len, NSZone* zone)
return NO;
}
att = [mgr fileAttributesAtPath: path traverseLink: YES];
if ([att fileType] != NSFileTypeRegular)
{
NSWarnFLog(@"Open (%@) attempt failed - not a regular file", path);
return NO;
}
#if defined(_WIN32)
theFile = _wfopen(thePath, L"rb");
#else
@ -280,11 +289,15 @@ readContentsOfFile(NSString* path, void** buf, off_t* len, NSZone* zone)
* file) by calling ftello().
*/
fileLength = ftello(theFile);
if (fileLength == (off_t) -1)
if (fileLength == (off_t)-1)
{
NSWarnFLog(@"Ftell on %@ failed - %@", path, [NSError _last]);
goto failure;
}
if (fileLength >= 2147483647)
{
fileLength = 0;
}
/*
* Rewind the file pointer to the beginning, preparing to read in