diff --git a/src/header/stdio/printf.rs b/src/header/stdio/printf.rs index d8b06bc70f3b4c4e964c9f0933a637d182c33f75..727de9526474e4d7b8f1109ff3c1f3be6a5c6778 100644 --- a/src/header/stdio/printf.rs +++ b/src/header/stdio/printf.rs @@ -472,7 +472,6 @@ struct PrintfArg { sign_always: bool, min_width: Number, precision: Option<Number>, - pad_space: Number, pad_zero: Number, intkind: IntKind, fmt: u8, @@ -596,7 +595,6 @@ impl Iterator for PrintfIter { sign_always, min_width, precision, - pad_space, pad_zero, intkind, fmt, @@ -667,8 +665,11 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) -> let sign_always = arg.sign_always; let min_width = arg.min_width.resolve(&mut varargs, &mut ap); let precision = arg.precision.map(|n| n.resolve(&mut varargs, &mut ap)); - let pad_space = arg.pad_space.resolve(&mut varargs, &mut ap); let pad_zero = arg.pad_zero.resolve(&mut varargs, &mut ap); + let pad_space = match pad_zero { + 0 => min_width, + _ => 0, + }; let intkind = arg.intkind; let fmt = arg.fmt; let fmtkind = arg.fmtkind; diff --git a/src/ld_so/linker.rs b/src/ld_so/linker.rs index 1b47d5c38e5583448199cf39beba434f4784af4a..4aea9b41008ff5fb893746e1a01129d750861a42 100644 --- a/src/ld_so/linker.rs +++ b/src/ld_so/linker.rs @@ -394,7 +394,7 @@ impl Linker { }; if same_elf { let addr = dso.as_ref().unwrap().base_addr; - let mut size = bounds.1; + let size = bounds.1; // Fill the gaps i the binary let mut ranges = Vec::new(); for ph in elf.program_headers.iter() { @@ -410,8 +410,6 @@ impl Linker { let mut start = addr; for (vaddr, vsize) in ranges.iter() { if start < addr + vaddr { - let gap_size = addr + vaddr - start; - size += gap_size; sys_mman::mmap( start as *mut c_void, addr + vaddr - start, @@ -668,7 +666,7 @@ impl Linker { set_u64(tm as u64); } reloc::R_X86_64_DTPOFF64 => { - set_u64((s + a) as u64); + set_u64(rel.r_offset as u64); } reloc::R_X86_64_GLOB_DAT | reloc::R_X86_64_JUMP_SLOT => { set_u64(s as u64); diff --git a/tests/Makefile b/tests/Makefile index eec484b0789d2c752087b76adbb8516909fbda18..a6f967a87288da206243943a0d86613a2e6cd1a6 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -41,6 +41,7 @@ EXPECT_NAMES=\ stdio/scanf \ stdio/setvbuf \ stdio/sprintf \ + stdio/printf_space_pad \ stdlib/a64l \ stdlib/alloc \ stdlib/atof \ diff --git a/tests/error.c b/tests/error.c index 5cbe10385dd4ca3c03c89da32f9e5e412ca93607..4170e1f4bea81dbd24a3a0d630cd926d5ac267fd 100644 --- a/tests/error.c +++ b/tests/error.c @@ -20,7 +20,7 @@ int main(void) { int ret2 = strerror_r(err, buf2, 3); printf("errno: %d = %s, return: %d\n", err, buf2, ret2); - char buf3[256]; + char buf3[256] = {0}; int ret3 = strerror_r(err, buf3, 0); printf("errno: %d = %s, return: %d\n", err, buf3, ret3); } diff --git a/tests/expected/stdio/printf_space_pad.stderr b/tests/expected/stdio/printf_space_pad.stderr new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/expected/stdio/printf_space_pad.stdout b/tests/expected/stdio/printf_space_pad.stdout new file mode 100644 index 0000000000000000000000000000000000000000..8e9107f35130c3e809d4f7c5eff17b72af19ce9a --- /dev/null +++ b/tests/expected/stdio/printf_space_pad.stdout @@ -0,0 +1 @@ +A B diff --git a/tests/stdio/printf_space_pad.c b/tests/stdio/printf_space_pad.c new file mode 100644 index 0000000000000000000000000000000000000000..9e9172826dda162c342c1da807c148eb0aee04c3 --- /dev/null +++ b/tests/stdio/printf_space_pad.c @@ -0,0 +1,4 @@ +#include <stdio.h> +int main() { + printf ("%s%*s\n","A", 3, "B"); +}