diff options
author | bptato <nincsnevem662@gmail.com> | 2023-10-18 12:36:07 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-10-18 12:36:07 +0200 |
commit | 305906b7439fa71b73a0330026057e21042288d6 (patch) | |
tree | 251dcfc6048732fb63229c4b95b80c51c35e440b /src/io | |
parent | b66ab79dd2139167ab1e5661892a5705e471a5e4 (diff) | |
download | chawan-305906b7439fa71b73a0330026057e21042288d6.tar.gz |
socketstream: get rid of pointer arithmetic
Diffstat (limited to 'src/io')
-rw-r--r-- | src/io/socketstream.nim | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/io/socketstream.nim b/src/io/socketstream.nim index 6b648003..2e56a4c7 100644 --- a/src/io/socketstream.nim +++ b/src/io/socketstream.nim @@ -18,9 +18,10 @@ proc sockReadData(s: Stream, buffer: pointer, len: int): int = assert len != 0 let s = SocketStream(s) let wasend = s.isend + let buffer = cast[ptr UncheckedArray[uint8]](buffer) if s.blk: while result < len: - let n = s.source.recv(cast[pointer](cast[int](buffer) + result), len - result) + let n = s.source.recv(addr buffer[result], len - result) if n < 0: if result == 0: result = n @@ -42,8 +43,9 @@ proc sockReadData(s: Stream, buffer: pointer, len: int): int = proc sockWriteData(s: Stream, buffer: pointer, len: int) = var i = 0 + let buffer = cast[ptr UncheckedArray[uint8]](buffer) while i < len: - let n = SocketStream(s).source.send(cast[pointer](cast[int](buffer) + i), len - i) + let n = SocketStream(s).source.send(addr buffer[i], len - i) if n < 0: raise newException(IOError, $strerror(errno)) i += n |