Commit Graph

548 Commits

Author SHA1 Message Date
Denys Vlasenko
e16a5223d2 bc: fix handling of "digits" above 9
function                                             old     new   delta
zxc_lex_next                                        1573    1608     +35
xc_parse_pushIndex                                    58      56      -2
xc_program_index                                      71      63      -8
zxc_program_num                                     1022     990     -32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 35/-42)             Total: -7 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-29 02:24:19 +01:00
Denys Vlasenko
1476760600 bc: rename config options
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-28 13:32:04 +01:00
Denys Vlasenko
7d32e25bf3 bc: prepare for char-by-char input handling
function                                             old     new   delta
peek_inbuf                                             -     292    +292
parse_lex_by_checking_eq_sign                          -      26     +26
eat_inbuf                                              -      22     +22
zbc_vm_execute_FILE                                   52      61      +9
bc_lex_lineComment                                    29      30      +1
zbc_lex_number                                       174     172      -2
bc_vm_run                                            104      99      -5
zbc_num_divmod                                       156     150      -6
bc_lex_file                                           24       -     -24
bc_lex_assign                                         26       -     -26
zbc_lex_next                                        1982    1587    -395
------------------------------------------------------------------------------
(add/remove: 3/2 grow/shrink: 2/4 up/down: 350/-458)         Total: -108 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-26 18:32:43 +01:00
Denys Vlasenko
94576d2b97 bc: fix interactive handling of comments in strings and quotes in comments
function                                             old     new   delta
zbc_lex_next                                        1965    1979     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-25 23:45:57 +01:00
Denys Vlasenko
8fac1c7740 dc: add two tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-25 20:50:41 +01:00
Denys Vlasenko
5fa74b9efc bc: allow {break} and {continue} (allow RBRACE to terminate them)
function                                             old     new   delta
zbc_parse_stmt_possibly_auto                        1599    1560     -39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-25 17:07:51 +01:00
Denys Vlasenko
badf683b0a dc: unbreak interactive mode - was trying to get next tokens instead of executing
function                                             old     new   delta
zbc_program_read                                       -     268    +268
zdc_program_printStream                                -     146    +146
zbc_program_exec                                    4046    4182    +136
zdc_program_execStr                                  472     512     +40
zdc_parse_exprs_until_eof                              -      26     +26
zbc_vm_process                                       740     765     +25
zbc_lex_next                                        2225    2240     +15
zdc_parse_expr                                       569     535     -34
zbc_program_pushArray                                147       -    -147
zdc_program_asciify                                  370       -    -370
------------------------------------------------------------------------------
(add/remove: 3/2 grow/shrink: 4/1 up/down: 656/-551)          Total: 105 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-22 18:10:50 +01:00
Denys Vlasenko
8c1e723596 bc: unbreak read(), remove checks for nested read()
function                                             old     new   delta
zbc_parse_pushSTR                                      -      65     +65
common_parse_expr                                      -      32     +32
bc_error_nested_read_call                             10       -     -10
bc_parse_expr_empty_ok                              1977    1963     -14
zdc_parse_expr                                       635     615     -20
zcommon_parse_expr                                    32       -     -32
zbc_program_exec                                    4064    4023     -41
bc_parse_pushSTR                                      65       -     -65
------------------------------------------------------------------------------
(add/remove: 2/3 grow/shrink: 0/3 up/down: 97/-182)           Total: -85 bytes
   text	   data	    bss	    dec	    hex	filename
 981661	    485	   7296	 989442	  f1902	busybox_old
 981540	    485	   7296	 989321	  f1889	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-22 01:34:10 +01:00
Denys Vlasenko
19eee8ed7c bc: fix for() to not leave data on stack
function                                             old     new   delta
zbc_parse_stmt_possibly_auto                        1665    1697     +32
zbc_vm_process                                       672     701     +29
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 61/0)               Total: 61 bytes
   text	   data	    bss	    dec	    hex	filename
 981656	    485	   7296	 989437	  f18fd	busybox_old
 981748	    485	   7296	 989529	  f1959	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-21 20:29:34 +01:00
Denys Vlasenko
52caa007e3 bc: for(;;) fix from upstream
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-21 00:35:22 +01:00
Denys Vlasenko
5acd14ba5b bc: fix keyword matching to not think "ifz" is the "if" keyword
function                                             old     new   delta
zbc_lex_next                                        2224    2225      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-20 16:48:50 +01:00
Denys Vlasenko
55f3cab7e9 bc: fix "echo -n '#foo' | bc" not eating last 'o'
function                                             old     new   delta
zdc_parse_expr                                       656     653      -3
bc_lex_lineComment                                    39      36      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-6)               Total: -6 bytes
   text	   data	    bss	    dec	    hex	filename
 981424	    485	   7296	 989205	  f1815	busybox_old
 981418	    485	   7296	 989199	  f180f	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-18 14:39:33 +01:00
Denys Vlasenko
4b72aebe80 bc: remove "error after expression parsing" check
It is misplaced: caller knows better what can or cannot follow the expression.
Sometimes even caller's caller: "if (1) return a+b else..." -
parser of "return" does not know that "else" after it is valid,
parser of stmt does not know it either, - only parser of
"if" knows it!

The removed code balked on e.g. "{ print 1 }" statement.

This does not break any valid programs, but starts accepting some
invalid ones, e.g. "print 1 print 2" would work.

function                                             old     new   delta
zcommon_parse_expr                                    40      32      -8
zbc_parse_name                                       509     494     -15
zbc_parse_stmt_possibly_auto                        1678    1638     -40
bc_parse_expr_empty_ok                              2025    1977     -48
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-111)           Total: -111 bytes
   text	   data	    bss	    dec	    hex	filename
 981599	    485	   7296	 989380	  f18c4	busybox_old
 981488	    485	   7296	 989269	  f1855	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-17 17:00:29 +01:00
Denys Vlasenko
266aa00012 bc: store only index in p->exits, it's the only thing used there
function                                             old     new   delta
zbc_parse_stmt_possibly_auto                        1967    1964      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3)               Total: -3 bytes
   text	   data	    bss	    dec	    hex	filename
 981937	    485	   7296	 989718	  f1a16	busybox_old
 981934	    485	   7296	 989715	  f1a13	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-16 23:24:25 +01:00
Denys Vlasenko
de24e9d366 bc: remove redundant JUMP generation when parsing 'while'
function                                             old     new   delta
zbc_parse_stmt_possibly_auto                        2065    2025     -40
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-40)             Total: -40 bytes
   text	   data	    bss	    dec	    hex	filename
 982035	    485	   7296	 989816	  f1a78	busybox_old
 981995	    485	   7296	 989776	  f1a50	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-16 23:02:22 +01:00
Denys Vlasenko
06ade77002 bc: simplify use of "ip" in loop parsing functions
function                                             old     new   delta
zbc_parse_stmt_possibly_auto                        2106    2065     -41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-41)             Total: -41 bytes
   text	   data	    bss	    dec	    hex	filename
 982076	    485	   7296	 989857	  f1aa1	busybox_old
 982035	    485	   7296	 989816	  f1a78	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-16 22:44:51 +01:00
Denys Vlasenko
5d18f6be90 bc: fix "print 1,2,3" parsing
function                                             old     new   delta
zbc_parse_stmt_possibly_auto                        2245    2180     -65
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-65)             Total: -65 bytes
   text	   data	    bss	    dec	    hex	filename
 982237	    485	   7296	 990018	  f1b42	busybox_old
 982152	    485	   7296	 989933	  f1aed	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-16 21:08:30 +01:00
Denys Vlasenko
a50576a415 bc: fold zbc_parse_else() into its only caller
While at it, allow newline between "else" and its body

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-16 19:21:57 +01:00
Denys Vlasenko
202dd1943c bc: fixes for multi-line if/while/for
function                                             old     new   delta
zbc_vm_process                                       561     589     +28
zbc_lex_next_and_skip_NLINE                            -      22     +22
zbc_parse_stmt_possibly_auto                        2232    2253     +21
zbc_lex_skip_if_at_NLINE                               -      14     +14
zbc_lex_number                                       192     200      +8
zbc_num_divmod                                       150     156      +6
bc_vm_run                                            134     139      +5
bc_vm_init                                           757     760      +3
bc_num_printNewline                                   51      54      +3
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 7/0 up/down: 110/0)             Total: 110 bytes
   text	   data	    bss	    dec	    hex	filename
 982138	    485	   7296	 989919	  f1adf	busybox_old
 982275	    485	   7296	 990056	  f1b68	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-16 17:30:35 +01:00
Denys Vlasenko
e9519e44a6 bc: fix handling of 'return' not in functions, and 'define f()<newline>{...}'
function                                             old     new   delta
zbc_vm_process                                       561     597     +36
zbc_parse_stmt_possibly_auto                        2232    2253     +21
zbc_lex_number                                       192     200      +8
zbc_num_divmod                                       150     156      +6
bc_vm_run                                            134     139      +5
bc_vm_init                                           757     760      +3
bc_num_printNewline                                   51      54      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/0 up/down: 82/0)               Total: 82 bytes
   text	   data	    bss	    dec	    hex	filename
 982138	    485	   7296	 989919	  f1adf	busybox_old
 982247	    485	   7296	 990028	  f1b4c	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-16 17:06:07 +01:00
Denys Vlasenko
d1d29b4245 bc: partially rewrite parser, tests pass, ^C might be broken now
The entire control construct (if/while/for/funcdef) or {} block is
"eaten" by the corresponding parsing function, instead of maintaining
special "block flag stack" with magic bits in it, and returning to main
input loop after every inner statement (every input line, essentially).

This required moving line input deep into lexer - now zbc_lex_next()
triggers more reading when needed.

"block flag stack" is gone.

Correctness of ^C handling wasn't checked, might need fixing now.

if/else syntax is changed to match GNU bc: "else" can not be on
the next line (the rationale is that "if (1) 2" statement in interactive
mode should execute and print 2 instead of waiting for possible
"else ..." line).

This change fixes the following examples:

if (1) if (1) 1 else 2 else 3

if (0) 1 else if (1) 2

define w() { auto z; return 1; }

function                                             old     new   delta
zbc_parse_stmt_possibly_auto                           -    2232   +2232
zbc_vm_process                                        89     561    +472
zbc_lex_next                                        1982    2296    +314
bc_vm_init                                           749     757      +8
bc_parse_expr_empty_ok                              2016    2021      +5
bc_num_printNewline                                   54      51      -3
zbc_program_read                                     289     280      -9
bc_parse_free                                         47      38      -9
bc_parse_reset                                       126     113     -13
bc_parse_create                                      108      92     -16
bc_parse_push_block_flag                              47       -     -47
bc_parse_noElse                                       48       -     -48
zbc_parse_text_init                                  113      59     -54
zbc_parse_body                                       121       -    -121
zbc_parse_else                                       125       -    -125
zbc_parse_endBody                                    254       -    -254
bc_vm_run                                            421     134    -287
zbc_parse_auto                                       290       -    -290
zcommon_parse                                        476       -    -476
zbc_parse_stmt                                      1682       7   -1675
------------------------------------------------------------------------------
(add/remove: 1/7 grow/shrink: 4/8 up/down: 3031/-3427)       Total: -396 bytes
   text	   data	    bss	    dec	    hex	filename
 982586	    485	   7296	 990367	  f1c9f	busybox_old
 982138	    485	   7296	 989919	  f1adf	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-16 16:10:38 +01:00
Denys Vlasenko
99b3762335 bc: lexer debugging, added some failing test cases
function                                             old     new   delta
bc_parse_push_block_flag                               -      47     +47
zbc_parse_body                                       107     121     +14
zbc_num_divmod                                       156     150      -6
zbc_lex_number                                       200     192      -8
zbc_parse_endBody                                    264     254     -10
bc_parse_startBody                                    47       -     -47
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/3 up/down: 61/-71)            Total: -10 bytes
   text	   data	    bss	    dec	    hex	filename
 982596	    485	   7296	 990377	  f1ca9	busybox_old
 982586	    485	   7296	 990367	  f1c9f	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-15 20:06:59 +01:00
Denys Vlasenko
818b602c88 bc: fix another thinko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-13 17:56:35 +01:00
Denys Vlasenko
766f67250f bc: fix comment handling
function                                             old     new   delta
bc_vm_run                                            514     513      -1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-13 17:43:23 +01:00
Denys Vlasenko
9a23b07c4c testsuite: add bc and dc tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-12 21:41:40 +01:00
Denys Vlasenko
a133137174 dc: fix testsuite
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-06 18:46:42 +01:00
Chen Qi
572dfb8e78 testsuite: check CONFIG_DESKTOP before using 'od -t'
The '-t' option for od is enabled by CONFIG_DESKTOP. So
check this config before using 'od -t' in test cases.

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-27 16:57:36 +01:00
Bernhard Reutner-Fischer
3db4e7f84c printf: fix printing +-prefixed numbers
Thanks to Cristian Ionescu-Idbohrn for noticing.

Also fix "%d" '  42' to skip leading whitespace.

function                                             old     new   delta
print_direc                                          435     454     +19
bb_strtoll                                            99     103      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 23/0)               Total: 23 bytes

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2018-10-19 15:27:42 +02:00
Thomas De Schampheleire
6608879d34 head: convert existing tests to new-style
Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-09-22 19:40:35 +02:00
Thomas De Schampheleire
e0f617699f head: add test case for negative -n invocation
Commit 2da9724b56 broke 'head -n -1' and was
later reverted with 0d598ab9f0.

This commit adds a test case to avoid future breakage.

Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-09-22 19:40:35 +02:00
Denys Vlasenko
e5d5f5b9a7 hexdump: fix short file of zero butes treated as dup
function                                             old     new   delta
bb_dump_dump                                        1466    1491     +25

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-03 16:29:06 +02:00
Denys Vlasenko
335766602b testsuite/mount.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-28 14:10:00 +02:00
Denys Vlasenko
4c58f246d4 testsuite/pidof.tests: fix false positive take 2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 14:50:00 +02:00
Denys Vlasenko
332a191e7f testsuite/tar.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 14:35:56 +02:00
Denys Vlasenko
33eae28710 testsuite/pidof.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 14:26:21 +02:00
Denys Vlasenko
94593799f7 testsuite/bzcat.tests: fix false positive take 2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 13:15:10 +02:00
Denys Vlasenko
d8799b90f3 testsuite/unexpand/unexpand-works-like-GNU: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 12:54:57 +02:00
Denys Vlasenko
a429d5d0f3 testsuite/bzcat.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 10:35:45 +02:00
Denys Vlasenko
5738823dff testsuite/tar.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 10:01:49 +02:00
Denys Vlasenko
751005020d testsuite/cat.tests: fix false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-27 09:57:30 +02:00
Denys Vlasenko
a36986bb80 unlzma: close another SEGV possibility
function                                             old     new   delta
unpack_lzma_stream                                  2669    2686     +17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-25 17:03:46 +02:00
Harald van Dijk
8c24af9dcf tar: fix interaction of delayed symlink and hardlink creation
function                                             old     new   delta
create_or_remember_link                                -     106    +106
create_links_from_list                                 -      93     +93
find_applet_by_name                                  124     128      +4
unzip_main                                          2724    2726      +2
data_extract_all                                     891     873     -18
create_symlinks_from_list                             64       -     -64
create_or_remember_symlink                            94       -     -94
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 2/1 up/down: 205/-176)           Total: 29 bytes

Signed-off-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-22 17:34:31 +02:00
Denys Vlasenko
d80eecb868 cat: fix cat -e and cat -v erroneously numbering 1st line
function                                             old     new   delta
cat_main                                             418     421      +3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-29 14:05:43 +02:00
Denys Vlasenko
2454e678cb awk: do not allow $(-1)
function                                             old     new   delta
EMSG_NEGATIVE_FIELD                                    -      25     +25
evaluate                                            3390    3403     +13
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 38/0)               Total: 38 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-23 10:53:18 +02:00
Denys Vlasenko
e09c426456 unlzma: fix another SEGV case
function                                             old     new   delta
unpack_lzma_stream                                  1705    1717     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-19 19:30:51 +02:00
Ron Yorston
1f27fa9838 testsuite: allow tests to work in paths containing spaces
Tweak some tests so they work when the path to the test directory or
$HOME contains spaces.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-09 20:35:48 +02:00
Denys Vlasenko
a1870f4807 unlzma: fix segfault on bad archive
function                                             old     new   delta
unpack_lzma_stream                                  2647    2653      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 20:45:16 +02:00
Denys Vlasenko
38ccd6af8a bzip2: fix two crashes on corrupted archives
As it turns out, longjmp'ing into freed stack is not healthy...

function                                             old     new   delta
unpack_usage_messages                                  -      97     +97
unpack_bz2_stream                                    369     409     +40
get_next_block                                      1667    1677     +10
get_bits                                             156     155      -1
start_bunzip                                         212     183     -29
bb_show_usage                                        181     120     -61
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/3 up/down: 147/-91)            Total: 56 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-08 20:05:04 +02:00
Denys Vlasenko
03fd7e06f8 grep: fix echo "aa" | busybox grep -F -w "a" (should not match)
function                                             old     new   delta
grep_file                                           1461    1470      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-29 18:03:50 +02:00
Denys Vlasenko
a84db18fc7 tar,unzip: postpone creation of symlinks with "suspicious" targets
This mostly reverts commit bc9bbeb2b8
"libarchive: do not extract unsafe symlinks unless $EXTRACT_UNSAFE_SYMLINKS=1"

Users report that it is somewhat too restrictive. See
https://bugs.busybox.net/show_bug.cgi?id=8411

In particular, this interferes with unpacking of busybox-based
filesystems with links like "sbin/applet" -> "../bin/busybox".

The change is made smaller by deleting ARCHIVE_EXTRACT_QUIET flag -
it is unused since 2010, and removing conditionals on it
allows commonalizing some error message codes.

function                                             old     new   delta
create_or_remember_symlink                             -      94     +94
create_symlinks_from_list                              -      64     +64
tar_main                                            1002    1006      +4
unzip_main                                          2732    2724      -8
data_extract_all                                     984     891     -93
unsafe_symlink_target                                147       -    -147
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 1/2 up/down: 162/-248)          Total: -86 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-20 16:06:53 +01:00