Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Patch

- Fix panic when printing the help, version, or specification output fails
- Fix panic when the block value is too large
- Fix inaccurate error positions when decoding by small blocks with ignored characters
- Fix panic when the width value is not a multiple of the base or is too large
Expand Down
22 changes: 12 additions & 10 deletions bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ macro_rules! check {
};
}

macro_rules! println {
($($x:tt)*) => {{
let mut stdout = std::io::stdout();
let result = writeln!(stdout, $($x)*).map_err(Error::Write);
result.and_then(|()| stdout.flush().map_err(Error::Write))
}};
}

#[derive(Debug)]
pub enum Error {
ParseOpts(getopts::Fail),
Expand Down Expand Up @@ -227,7 +235,7 @@ fn wrapped_main(program: &str, args: Vec<String>) -> Result<()> {
r"Usage: {program} --mode=<mode> --base=<base> [<options>]
Usage: {program} --mode=<mode> --symbols=<symbols> [<options>]"
);
print!(
return println!(
"{0}
Examples:
# Using the RFC4648 base64 encoding
Expand All @@ -246,17 +254,14 @@ Examples:
{1} --mode=decode \\
--symbols=0123456789bcdfghjklmnpqrstuvwxyz \\
--translate=BCDFGHJKLMNPQRSTUVWXYZbcdfghjklmnpqrstuvwxyz \\
--least_significant_bit_first
",
--least_significant_bit_first",
opts.usage(&brief),
program
);
return Ok(());
}

if args.len() == 1 && (args[0] == "--version" || args[0] == "-v") {
println!("{}", env!("CARGO_PKG_VERSION"));
return Ok(());
return println!("{}", env!("CARGO_PKG_VERSION"));
}

let matches = opts.parse(&args).map_err(Error::ParseOpts)?;
Expand Down Expand Up @@ -324,10 +329,7 @@ Examples:
"" => return Err(Error::Cmdline("Empty mode".into())),
x if "encode".starts_with(x) => true,
x if "decode".starts_with(x) => false,
x if "specification".starts_with(x) => {
println!("{:#?}", base.specification());
return Ok(());
}
x if "specification".starts_with(x) => return println!("{:#?}", base.specification()),
_ => return Err(Error::Cmdline("Invalid mode".into())),
};

Expand Down
3 changes: 3 additions & 0 deletions bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ if [ -e /dev/full ]; then
'Write error: No space left on device (os error 28)'
unit '-md -b64 -p= -o /dev/full' Zm9v '' \
'Write error: No space left on device (os error 28)'
unit '-ms -b64 >/dev/full' '' '' 'Write error: No space left on device (os error 28)'
unit '--version >/dev/full' '' '' 'Write error: No space left on device (os error 28)'
unit '--help >/dev/full' '' '' 'Write error: No space left on device (os error 28)'
fi
echo
echo -n 'custom:'
Expand Down
Loading