Skip to content

Commit

Permalink
Fix length on dump
Browse files Browse the repository at this point in the history
Happened if aligned size was greater than requested length
  • Loading branch information
dd86k committed Apr 29, 2022
1 parent 9153780 commit fac227c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ddhx/ddhx.d
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,12 @@ int ddhxDump(long skip, long length) {
displayRenderTopRaw();

// mitigate unaligned reads/renders
io.resizeBuffer(globals.rowWidth * 16);
uint a = globals.rowWidth * 16;
io.resizeBuffer(a);

if (a > length) {
io.resizeBuffer(cast(uint)length);
}

// read until EOF or length spec
long r;
Expand Down
7 changes: 7 additions & 0 deletions src/ddhx/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ struct IoState {
// Mostly-stateless, lazy implementation of a FILE using direct OS
// functions, since File under x86-omf builds seem iffy, broken
// (especially when attempting to get the size of a large file).
//TODO: redo read functions with a simpler api
// e.g., ubyte[] read(ubyte[] buffer)
// on error, sets bool error = true;
// or int error = OS errorcode
//TODO: Move this to os.file
private struct OSFile {
private OSHANDLE handle;
private bool eof;
Expand Down Expand Up @@ -144,6 +149,7 @@ private struct OSFile {
}

int seek(ref long npos, Seek origin, long pos) {
version (Trace) trace("origin=%u pos=%u", origin, pos);
version (Windows) {
LARGE_INTEGER liIn = void, liOut = void;
liIn.QuadPart = pos;
Expand All @@ -160,6 +166,7 @@ private struct OSFile {
}

int read(ref ubyte[] result, ubyte[] buffer) {
version (Trace) trace("buffer.length=%u", buffer.length);
version (Windows) {
const uint len = cast(uint)buffer.length;
uint r = void; /// size read
Expand Down
3 changes: 3 additions & 0 deletions src/ddhx/terminal.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
/// Authors: $(LINK2 github.com/dd86k, dd86k)
module ddhx.terminal;

//TODO: Move this to os.terminal
//TODO: Register function for terminal size change
// Under Windows, that's under a regular input event
// Under Linux, that's under a signal (and function pointer)
//TODO: readline
// automatically pause input, stdio.readln, resume input

// NOTE: Useful links for escape codes
// https://man7.org/linux/man-pages/man0/termios.h.0p.html
Expand Down

0 comments on commit fac227c

Please sign in to comment.