From daa0095507bf847675c529a78d96f7ac4b561eee Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 20 Dec 2024 12:47:14 +0100 Subject: Do not spit out bytes if -Werror was passed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Even if there are no errors, if warnings are to be treated as errors then the output should behave the same as if they were errors. That is, in case there are warnings and they are to be treated as errors, then do not spit out any assembled bundle. Signed-off-by: Miquel Sabaté Solà --- crates/nasm/src/main.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/nasm/src/main.rs b/crates/nasm/src/main.rs index 646e249..c5c72ae 100644 --- a/crates/nasm/src/main.rs +++ b/crates/nasm/src/main.rs @@ -94,9 +94,19 @@ fn main() -> Result<()> { let mut assembler = Assembler::new(mapping); match assembler.assemble(working_directory.to_path_buf(), input) { Ok(bundles) => { - for b in bundles { - for i in 0..b.size { - output.write_all(&[b.bytes[i as usize]])?; + for warning in assembler.warnings() { + if warn_as_errors { + println!("{}", warning); + error_count += 1; + } else { + println!("Warning: {}", warning); + } + } + if error_count == 0 { + for b in bundles { + for i in 0..b.size { + output.write_all(&[b.bytes[i as usize]])?; + } } } } @@ -107,12 +117,6 @@ fn main() -> Result<()> { } } } - for warning in assembler.warnings() { - println!("Warning: {}", warning); - if warn_as_errors { - error_count += 1; - } - } std::process::exit(error_count); } -- cgit v1.2.3