authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-01-19 22:05:56+01:00
committergravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-01-19 22:05:56+01:00
loga1a69f24c846fdd8a7682216c383df53963b5b3b
tree77d1d6cefa80907b554f70e61e75384f06a07c4f
parent61497893d312e9e9bf5dd0c3d6fe232091ce8045

We now make a more correct conversion from windows LARGE_INTEGER type to usize


1 files changed, 9 insertions(+), 3 deletions(-)

std/io.zig+9-3
...@@ -48,6 +48,7 @@ error PathNotFound;...@@ -48,6 +48,7 @@ error PathNotFound;
48error OutOfMemory;48error OutOfMemory;
49error Unseekable;49error Unseekable;
50error EndOfFile;50error EndOfFile;
51error FilePosLargerThanPointerRange;
5152
52pub fn getStdErr() -> %File {53pub fn getStdErr() -> %File {
53 const handle = if (is_windows)54 const handle = if (is_windows)
...@@ -266,8 +267,8 @@ pub const File = struct {...@@ -266,8 +267,8 @@ pub const File = struct {
266 return result;267 return result;
267 },268 },
268 Os.windows => {269 Os.windows => {
269 var pos : usize = undefined;270 var pos : system.LARGE_INTEGER = undefined;
270 if (system.SetFilePointerEx(self.handle, 0, @ptrCast(system.PLARGE_INTEGER, &pos), system.FILE_CURRENT) == 0) {271 if (system.SetFilePointerEx(self.handle, 0, &pos, system.FILE_CURRENT) == 0) {
271 const err = system.GetLastError();272 const err = system.GetLastError();
272 return switch (err) {273 return switch (err) {
273 system.ERROR.INVALID_PARAMETER => error.BadFd,274 system.ERROR.INVALID_PARAMETER => error.BadFd,
...@@ -275,7 +276,12 @@ pub const File = struct {...@@ -275,7 +276,12 @@ pub const File = struct {
275 };276 };
276 }277 }
277278
278 return pos;279 assert(pos >= 0);
280 if (pos > @maxValue(usize)) {
281 return error.FilePosLargerThanPointerRange;
282 }
283
284 return usize(pos);
279 },285 },
280 else => @compileError("unsupported OS"),286 else => @compileError("unsupported OS"),
281 }287 }