diff options
| author | 2024-09-26 23:08:46 -0400 | |
|---|---|---|
| committer | 2024-09-26 23:08:46 -0400 | |
| commit | cd554877c5f57cdebc919cd889c1812773446a1e (patch) | |
| tree | 6e4f4ca5a55a7faf859cd9cc6cbb897d75d0fa7e /src/lush.c | |
| parent | v0.2.1 (diff) | |
fixed crash in redirect operator
Diffstat (limited to 'src/lush.c')
| -rw-r--r-- | src/lush.c | 19 |
1 files changed, 9 insertions, 10 deletions
@@ -1126,13 +1126,8 @@ int lush_execute_chain(lua_State *L, char ***commands, int num_commands) { int last_result = 0; for (int i = 0; i < num_actions; i++) { - // Handle ; operator - if (is_operator(commands[0][0]) == OP_SEMICOLON) { - commands++; - } - - // Handle && and || operators - if (i > 0) { + // Handle &&, ||, and ; operators + if (i > 0 && commands[0] != NULL) { commands--; if (last_result != 0) { if (is_operator(commands[0][0]) == OP_AND) { @@ -1146,6 +1141,10 @@ int lush_execute_chain(lua_State *L, char ***commands, int num_commands) { } } commands++; + + if (is_operator(commands[0][0]) == OP_SEMICOLON) { + commands++; + } } // Handle other operations @@ -1174,15 +1173,15 @@ int lush_execute_chain(lua_State *L, char ***commands, int num_commands) { commands += 2; continue; } else if (op_type == OP_BACKGROUND) { - run_command_background(L, commands); + last_result = run_command_background(L, commands); commands += 2; continue; } else if (op_type == OP_REDIRECT_OUT) { - run_command_redirect(L, commands, O_TRUNC); + last_result = run_command_redirect(L, commands, O_TRUNC); commands += 3; // to go past fd given continue; } else if (op_type == OP_APPEND_OUT) { - run_command_redirect(L, commands, O_APPEND); + last_result = run_command_redirect(L, commands, O_APPEND); commands += 3; continue; } |
