check for a valid file and check for ftruncate() result and throw exception in case

This commit is contained in:
Riccardo Mottola 2023-09-18 23:40:13 +02:00
parent e20b3d59fc
commit 72e8335bd9

View file

@ -1880,9 +1880,16 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
- (void) truncateFileAtOffset: (unsigned long long)pos
{
if (isStandardFile && descriptor >= 0)
if (!(isStandardFile && descriptor >= 0))
{
(void)ftruncate(descriptor, pos);
[NSException raise: NSFileHandleOperationException
format: @"attempt to truncate invalid file"];
}
if (ftruncate(descriptor, pos) < 0)
{
[NSException raise: NSFileHandleOperationException
format: @"truncation failed"];
}
[self seekToFileOffset: pos];
}