From f3659d44155c76790ad65f8ed60e0ea430df5d7b Mon Sep 17 00:00:00 2001 From: zhanghuanhuan Date: Fri, 11 Aug 2023 15:42:01 +0800 Subject: [PATCH] fixed test suspend shift error --- bash-5.1/builtins_rust/exec_cmd/src/lib.rs | 3 +- bash-5.1/builtins_rust/read/src/lib.rs | 41 ++++++++-------------- bash-5.1/builtins_rust/setattr/src/lib.rs | 7 +++- bash-5.1/builtins_rust/shift/src/lib.rs | 4 +-- bash-5.1/builtins_rust/suspend/src/lib.rs | 6 ++-- record.txt | 1 + 6 files changed, 27 insertions(+), 35 deletions(-) diff --git a/bash-5.1/builtins_rust/exec_cmd/src/lib.rs b/bash-5.1/builtins_rust/exec_cmd/src/lib.rs index 0a31ece..6825fbe 100644 --- a/bash-5.1/builtins_rust/exec_cmd/src/lib.rs +++ b/bash-5.1/builtins_rust/exec_cmd/src/lib.rs @@ -864,7 +864,8 @@ unsafe fn get_cmd_type (command : *mut i8) -> CMDType{ types = CMDType::SuspendCmd; } - else if libc::strcmp(command,b"test\0" as *const u8 as *const i8 as *mut i8) == 0{ + else if libc::strcmp(command,b"test\0" as *const u8 as *const i8 as *mut i8) == 0 + || libc::strcmp(command,b"[\0" as *const u8 as *const i8 as *mut i8)== 0 { types = CMDType::TestCmd; } diff --git a/bash-5.1/builtins_rust/read/src/lib.rs b/bash-5.1/builtins_rust/read/src/lib.rs index da68f6e..5ca4bd4 100644 --- a/bash-5.1/builtins_rust/read/src/lib.rs +++ b/bash-5.1/builtins_rust/read/src/lib.rs @@ -159,7 +159,20 @@ unsafe { tmusec = uval as c_uint; } } - + 'N' | 'n' => { + if opt_char == 'N' { + ignore_delim = 1; + delim = -1; + } + nflag = 1; + code = legal_number(list_optarg, &mut intval); + if code == 0 || intval < 0 || intval != (intval as c_int) as c_long { + sh_invalidnum(list_optarg); + return EXECUTION_FAILURE; + } else { + nchars = intval as c_int; + } + } 'u' => { code = legal_number(list_optarg, &mut intval); if code == 0 || intval < 0 || intval != (intval as c_int) as c_long { @@ -180,32 +193,6 @@ unsafe { } _ => { - if (opt_char == 'N'){ - ignore_delim = 1; - delim = -1; - nflag = 1; - code = legal_number(list_optarg, &mut intval); - if code == 0 || intval < 0 || intval != (intval as c_int) as c_long { - sh_invalidnum(list_optarg); - return EXECUTION_FAILURE; - } else { - nchars = intval as c_int; - } - break; - } - if (opt_char == 'n') - { - nflag = 1; - code = legal_number(list_optarg, &mut intval); - if code == 0 || intval < 0 || intval != (intval as c_int) as c_long { - sh_invalidnum(list_optarg); - return EXECUTION_FAILURE; - } else { - nchars = intval as c_int; - } - break; - } - // builtin_usage(); r_builtin_usage (); return EX_USAGE; } diff --git a/bash-5.1/builtins_rust/setattr/src/lib.rs b/bash-5.1/builtins_rust/setattr/src/lib.rs index 3237cbe..2d8def2 100644 --- a/bash-5.1/builtins_rust/setattr/src/lib.rs +++ b/bash-5.1/builtins_rust/setattr/src/lib.rs @@ -1,3 +1,5 @@ +use std::mem::size_of_val; + use libc::{c_int, c_uint, c_char, c_long, PT_NULL, c_void}; include!(concat!("intercdep.rs")); @@ -185,7 +187,8 @@ unsafe { if !variable_list.is_null() { let mut i = 0; loop { - var = (variable_list as usize + 8 * i) as *mut SHELL_VAR; + var = *((variable_list as usize + (8*i))as *mut *mut SHELL_VAR) as *mut SHELL_VAR; + if var.is_null() { break; } @@ -193,10 +196,12 @@ unsafe { if arrays_only != 0 && ((*var).attributes & att_array) != 0 { continue; } else if assoc_only != 0 && ((*var).attributes & assoc_only) != 0 { + i += 1; continue; } if ((*var).attributes & (att_invisible | att_exported)) == (att_invisible | att_exported) { + i += 1; continue; } diff --git a/bash-5.1/builtins_rust/shift/src/lib.rs b/bash-5.1/builtins_rust/shift/src/lib.rs index 746196e..ae2d00a 100644 --- a/bash-5.1/builtins_rust/shift/src/lib.rs +++ b/bash-5.1/builtins_rust/shift/src/lib.rs @@ -33,9 +33,9 @@ unsafe { if times > nargs { if print_shift_error != 0 { let s = if list.is_null() {PT_NULL as *mut c_char} else {(*(*list).word).word}; - r_sh_erange(s,"shift count\0".as_ptr() as *mut c_char); - return EXECUTION_FAILURE; + r_sh_erange(s,"shift count\0".as_ptr() as *mut c_char); } + return EXECUTION_FAILURE; } else if times == nargs { clear_dollar_vars(); } else { diff --git a/bash-5.1/builtins_rust/suspend/src/lib.rs b/bash-5.1/builtins_rust/suspend/src/lib.rs index 3798740..bf5b428 100644 --- a/bash-5.1/builtins_rust/suspend/src/lib.rs +++ b/bash-5.1/builtins_rust/suspend/src/lib.rs @@ -14,7 +14,7 @@ pub extern "C" fn r_suspend_builtin(mut list: *mut WordList) -> i32 { unsafe { reset_internal_getopt(); - let opt_str = "f:\0".as_ptr() as *mut c_char; + let opt_str = "f\0".as_ptr() as *mut c_char; opt = internal_getopt (list, opt_str); while opt != -1 { let opt_char:char=char::from(opt as u8); @@ -25,15 +25,14 @@ unsafe { return EX_USAGE; } } + opt = internal_getopt (list, opt_str); } list = loptend; - if job_control == 0 { sh_nojobs("cannot suspend\0".as_ptr() as *mut c_char); return EXECUTION_FAILURE; } - if force == 0 { r_no_args(list); if login_shell != 0 { @@ -43,7 +42,6 @@ unsafe { } old_cont = set_signal_handler(libc::SIGCONT, std::mem::transmute(suspend_continue as usize)); - killpg(shell_pgrp, libc::SIGSTOP); } return EXECUTION_SUCCESS; diff --git a/record.txt b/record.txt index 250ff63..8ddf4bd 100644 --- a/record.txt +++ b/record.txt @@ -60,3 +60,4 @@ 59 60 61 +62 -- Gitee