digitalmars.D.bugs - std.stream.MemoryStream.writeBlock bug.
- Hiroshi Sakurai (17/17) Dec 12 2004 std.stream.MemoryStream.writeBlock bug.
- Ben Hinkle (10/33) Dec 12 2004 I don't think that is a bug. The "writeBlock" function takes a void* buf...
- Hiroshi Sakurai (5/38) Dec 13 2004 Thank you for a reply. Ben.
std.stream.MemoryStream.writeBlock bug. The size beyond the length of array is specified. Even the data of domains other than array will write out. source code import std.stream; void main() { MemoryStream ms = new MemoryStream(); byte[] b; b.length = 10; for (int i = 0; i < b.length; i++) { b[i] = i; } ms.writeBlock(b, 11); printf("length = %d\n", ms.data.length); } output 11
Dec 12 2004
Hiroshi Sakurai wrote:std.stream.MemoryStream.writeBlock bug. The size beyond the length of array is specified. Even the data of domains other than array will write out. source code import std.stream; void main() { MemoryStream ms = new MemoryStream(); byte[] b; b.length = 10; for (int i = 0; i < b.length; i++) { b[i] = i; } ms.writeBlock(b, 11); printf("length = %d\n", ms.data.length); } output 11I don't think that is a bug. The "writeBlock" function takes a void* buffer pointer and a length, so the fact that the buffer originally came from an array is forgotten inside writeBlock. To write out exactly a buffer try "write(ubyte[] buf)". I suppose you'll have to cast the buffer since byte[] isn't implicitly convertable to ubyte[]. In other words instead of ms.writeBlock(b,11) try ms.write(b); -Ben
Dec 12 2004
In article <cpipj0$6jv$1 digitaldaemon.com>, Ben Hinkle says...Hiroshi Sakurai wrote:Thank you for a reply. Ben. Well. I mistook about Phobos spec. -Hiroshi Sakuraistd.stream.MemoryStream.writeBlock bug. The size beyond the length of array is specified. Even the data of domains other than array will write out. source code import std.stream; void main() { MemoryStream ms = new MemoryStream(); byte[] b; b.length = 10; for (int i = 0; i < b.length; i++) { b[i] = i; } ms.writeBlock(b, 11); printf("length = %d\n", ms.data.length); } output 11I don't think that is a bug. The "writeBlock" function takes a void* buffer pointer and a length, so the fact that the buffer originally came from an array is forgotten inside writeBlock. To write out exactly a buffer try "write(ubyte[] buf)". I suppose you'll have to cast the buffer since byte[] isn't implicitly convertable to ubyte[]. In other words instead of ms.writeBlock(b,11) try ms.write(b); -Ben
Dec 13 2004