attempt fix for bug 29920

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@30471 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2010-05-29 08:05:03 +00:00
parent 6388ec9d4f
commit 44259dbf9e
2 changed files with 28 additions and 8 deletions

View file

@ -1,3 +1,7 @@
2010-05-29 Richard Frith-Macdonald <rfm@gnu.org>
* NSData.m: Attempted fix for bug #29920
2010-05-29 Richard Frith-Macdonald <rfm@gnu.org>
* NSConcreteHashTable.m:

View file

@ -169,7 +169,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
NSDebugFLog(@"Open (%@) attempt failed - %@", path, [NSError _last]);
goto failure;
}
/*
* Seek to the end of the file.
*/
@ -203,7 +203,8 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
[NSError _last]);
goto failure;
}
clearerr(theFile);
if (fileLength == 0)
{
unsigned char buf[BUFSIZ];
@ -246,6 +247,8 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
}
else
{
long offset = 0;
#if GS_WITH_GC
tmp = NSAllocateCollectable(fileLength, 0);
#else
@ -258,15 +261,28 @@ readContentsOfFile(NSString* path, void** buf, unsigned int* len, NSZone* zone)
goto failure;
}
c = fread(tmp, 1, fileLength, theFile);
if (c != (int)fileLength)
while (offset < fileLength
&& (c = fread(tmp + offset, 1, fileLength - offset, theFile)) != 0)
{
NSWarnFLog(@"read of file (%@) contents failed - %@", path,
[NSError _last]);
goto failure;
offset += c;
}
if (offset < fileLength)
{
fileLength = offset;
#if GS_WITH_GC
tmp = NSReallocateCollectable(tmp, fileLength, 0);
#else
tmp = NSZoneRealloc(zone, tmp, fileLength);
#endif
}
}
if (ferror(theFile))
{
NSWarnFLog(@"read of file (%@) contents failed - %@", path,
[NSError _last]);
goto failure;
}
*buf = tmp;
*len = fileLength;
fclose(theFile);