sharkdp / hexyl

A command-line hex viewer
Apache License 2.0
8.92k stars 227 forks source link

Argument `--skip` with negative offset larger than file size will print a generic error. #114

Closed eth-p closed 3 years ago

eth-p commented 3 years ago

I'm not too sure how other platforms handle this one, but on MacOS it will print "Error: Invalid argument (os error 22)" and then immediately exit with exit code 1.

Example:

$ hexyl "$(which hexyl)" --skip=-5gib
Error: Invalid argument (os error 22)

Note: I'm doing a class assignment regarding creating tests (from scratch) for an open-source command line program, and I chose hexyl for it. You might have a couple more of these on the way, depending on what the assignment brings to light :)

sharkdp commented 3 years ago

Thanks. A nicer error message would be great, yes.

ErichDonGubler commented 3 years ago

Disclaimer: I'm interested in resolving this. Right now, I'm just going to triage things, but I hope to have a solution after I finish researching and put in my vote for my elections as a US resident.

This is interesting -- on my Windows machine, I get very different results:

$ echo asdf > large-negative-seek-wont-work-here

$ hexyl large-negative-seek-wont-work-here --skip=-2
┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
│00000000│ 61 73 64 66 0a          ┊                         │asdf_   ┊        │
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘

$ hexyl large-negative-seek-wont-work-here --skip=-2gib
┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
│00000000│ 61 73 64 66 0a          ┊                         │asdf_   ┊        │
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘

$ hexyl large-negative-seek-wont-work-here --skip=-1
┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
│00000000│ 61 73 64 66 0a          ┊                         │asdf_   ┊        │
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘

Yuck.

sharkdp commented 3 years ago

@ErichDonGubler are you using latest master on Windows? I just added some tests in #122 and they seem to succeed on Windows. If the issues persist, could you please open a new ticket?

I also updated the error message, so this ticket can be closed.