diff options
-rw-r--r-- | parse.c | 24 | ||||
-rwxr-xr-x | tests.sh | 8 | ||||
-rw-r--r-- | tests/test_xtype_reorder.out | 0 |
3 files changed, 29 insertions, 3 deletions
@@ -1003,10 +1003,20 @@ static struct expr *parse_depth_limit(struct parser_state *state, int is_min, in */ static struct expr *parse_empty(struct parser_state *state, int arg1, int arg2) { struct expr *expr = parse_nullary_test(state, eval_empty); - if (expr) { - expr->cost = 2000.0; - expr->probability = 0.01; + if (!expr) { + return NULL; + } + + expr->cost = 2000.0; + expr->probability = 0.01; + + if (state->cmdline->optlevel < 4) { + // Since -empty attempts to open and read directories, it may + // have side effects such as reporting permission errors, and + // thus shouldn't be re-ordered without aggressive optimizations + expr->pure = false; } + return expr; } @@ -2103,6 +2113,14 @@ static struct expr *parse_type(struct parser_state *state, int x, int arg2) { expr->idata = types; expr->probability = probability; + + if (x && state->cmdline->optlevel < 4) { + // Since -xtype dereferences symbolic links, it may have side + // effects such as reporting permission errors, and thus + // shouldn't be re-ordered without aggressive optimizations + expr->pure = false; + } + return expr; fail: @@ -374,6 +374,7 @@ gnu_tests=( bfs_tests=( test_type_multi test_xtype_multi + test_xtype_reorder test_perm_symbolic_trailing_comma test_perm_symbolic_double_comma test_perm_symbolic_missing_action @@ -755,6 +756,13 @@ function test_xtype_multi() { bfs_diff links -xtype f,d,c 2>/dev/null } +function test_xtype_reorder() { + # Make sure -xtype is not reordered in front of anything -- if -xtype runs + # before -links 100, it will report an ELOOP error + bfs_diff links -links 100 -xtype l + invoke_bfs links -links 100 -xtype l +} + function test_iname() { bfs_diff basic -iname '*F*' } diff --git a/tests/test_xtype_reorder.out b/tests/test_xtype_reorder.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/test_xtype_reorder.out |