Skip to content

Commit

Permalink
Fix error code checking for SetFilePointer() call
Browse files Browse the repository at this point in the history
An error has occurred if the return value is invalid_set_file_pointer
and getlasterror doesn't return no_error.

Signed-off-by: Fabien Chouteau <chouteau@adacore.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
Fabien-Chouteau authored and kevmw committed Dec 11, 2012
1 parent 473c7f0 commit fbcad04
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions block/raw-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,24 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset)
{
BDRVRawState *s = bs->opaque;
LONG low, high;
DWORD dwPtrLow;

low = offset;
high = offset >> 32;
if (!SetFilePointer(s->hfile, low, &high, FILE_BEGIN))
return -EIO;
if (!SetEndOfFile(s->hfile))

/*
* An error has occurred if the return value is INVALID_SET_FILE_POINTER
* and GetLastError doesn't return NO_ERROR.
*/
dwPtrLow = SetFilePointer(s->hfile, low, &high, FILE_BEGIN);
if (dwPtrLow == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) {
fprintf(stderr, "SetFilePointer error: %d\n", GetLastError());
return -EIO;
}
if (SetEndOfFile(s->hfile) == 0) {
fprintf(stderr, "SetEndOfFile error: %d\n", GetLastError());
return -EIO;
}
return 0;
}

Expand Down

0 comments on commit fbcad04

Please sign in to comment.