diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-03 20:35:16 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-05 15:43:35 +0100 |
| commit | a02f84472a9508e499f0eecd748929a44f5d3869 (patch) | |
| tree | 95d2a1ab874ad81396784ad57605ca19cf8401bf /miscutils | |
| parent | bc5ce66617b6aa32b0ff7b51435cfc2c00c8ea89 (diff) | |
| download | busybox-w32-a02f84472a9508e499f0eecd748929a44f5d3869.tar.gz busybox-w32-a02f84472a9508e499f0eecd748929a44f5d3869.tar.bz2 busybox-w32-a02f84472a9508e499f0eecd748929a44f5d3869.zip | |
bc: BC_STATUS_VEC_ITEM_EXISTS is not a real error code, its message was never used
It was only used to indicate rusult of bc_map_insert() - did we insert, or
did we find that this key is already in the map?
function old new delta
bc_map_insert 142 145 +3
bc_program_addFunc 226 225 -1
bc_err_msgs 184 180 -4
bc_program_search 152 143 -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 3/-14) Total: -11 bytes
text data bss dec hex filename
987904 485 7296 995685 f3165 busybox_old
987873 485 7296 995654 f3146 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/bc.c | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index ecd19cb0b..b57f741d6 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
| @@ -217,7 +217,8 @@ typedef enum BcStatus { | |||
| 217 | BC_STATUS_EXEC_STACK, | 217 | BC_STATUS_EXEC_STACK, |
| 218 | 218 | ||
| 219 | // BC_STATUS_VEC_OUT_OF_BOUNDS, | 219 | // BC_STATUS_VEC_OUT_OF_BOUNDS, |
| 220 | BC_STATUS_VEC_ITEM_EXISTS, | 220 | // BC_STATUS_VEC_ITEM_EXISTS, |
| 221 | BC_STATUS_BEFORE_POSIX = BC_STATUS_EXEC_STACK, | ||
| 221 | #if ENABLE_BC | 222 | #if ENABLE_BC |
| 222 | BC_STATUS_POSIX_NAME_LEN, | 223 | BC_STATUS_POSIX_NAME_LEN, |
| 223 | BC_STATUS_POSIX_COMMENT, | 224 | BC_STATUS_POSIX_COMMENT, |
| @@ -288,7 +289,7 @@ static const char *const bc_err_msgs[] = { | |||
| 288 | "stack has too few elements", | 289 | "stack has too few elements", |
| 289 | 290 | ||
| 290 | // "index is out of bounds", | 291 | // "index is out of bounds", |
| 291 | "item already exists", | 292 | // "item already exists", |
| 292 | #if ENABLE_BC | 293 | #if ENABLE_BC |
| 293 | "POSIX only allows one character names; the following is bad:", | 294 | "POSIX only allows one character names; the following is bad:", |
| 294 | "POSIX does not allow '#' script comments", | 295 | "POSIX does not allow '#' script comments", |
| @@ -1276,20 +1277,17 @@ static size_t bc_map_find(const BcVec *v, const void *ptr) | |||
| 1276 | return low; | 1277 | return low; |
| 1277 | } | 1278 | } |
| 1278 | 1279 | ||
| 1279 | static BcStatus bc_map_insert(BcVec *v, const void *ptr, size_t *i) | 1280 | static int bc_map_insert(BcVec *v, const void *ptr, size_t *i) |
| 1280 | { | 1281 | { |
| 1281 | BcStatus s = BC_STATUS_SUCCESS; | 1282 | size_t n = *i = bc_map_find(v, ptr); |
| 1282 | |||
| 1283 | *i = bc_map_find(v, ptr); | ||
| 1284 | 1283 | ||
| 1285 | if (*i == v->len) | 1284 | if (n == v->len) |
| 1286 | bc_vec_push(v, ptr); | 1285 | bc_vec_push(v, ptr); |
| 1287 | else if (!bc_id_cmp(ptr, bc_vec_item(v, *i))) | 1286 | else if (!bc_id_cmp(ptr, bc_vec_item(v, n))) |
| 1288 | s = BC_STATUS_VEC_ITEM_EXISTS; | 1287 | return 0; // "was not inserted" |
| 1289 | else | 1288 | else |
| 1290 | bc_vec_pushAt(v, ptr, *i); | 1289 | bc_vec_pushAt(v, ptr, n); |
| 1291 | 1290 | return 1; // "was inserted" | |
| 1292 | return s; | ||
| 1293 | } | 1291 | } |
| 1294 | 1292 | ||
| 1295 | static size_t bc_map_index(const BcVec *v, const void *ptr) | 1293 | static size_t bc_map_index(const BcVec *v, const void *ptr) |
| @@ -5240,20 +5238,18 @@ static BcStatus common_parse_expr(BcParse *p, uint8_t flags) | |||
| 5240 | 5238 | ||
| 5241 | static BcVec* bc_program_search(char *id, bool var) | 5239 | static BcVec* bc_program_search(char *id, bool var) |
| 5242 | { | 5240 | { |
| 5243 | BcStatus s; | ||
| 5244 | BcId e, *ptr; | 5241 | BcId e, *ptr; |
| 5245 | BcVec *v, *map; | 5242 | BcVec *v, *map; |
| 5246 | size_t i; | 5243 | size_t i; |
| 5247 | BcResultData data; | 5244 | BcResultData data; |
| 5248 | bool new; | 5245 | int new; |
| 5249 | 5246 | ||
| 5250 | v = var ? &G.prog.vars : &G.prog.arrs; | 5247 | v = var ? &G.prog.vars : &G.prog.arrs; |
| 5251 | map = var ? &G.prog.var_map : &G.prog.arr_map; | 5248 | map = var ? &G.prog.var_map : &G.prog.arr_map; |
| 5252 | 5249 | ||
| 5253 | e.name = id; | 5250 | e.name = id; |
| 5254 | e.idx = v->len; | 5251 | e.idx = v->len; |
| 5255 | s = bc_map_insert(map, &e, &i); | 5252 | new = bc_map_insert(map, &e, &i); // 1 if insertion was successful |
| 5256 | new = s != BC_STATUS_VEC_ITEM_EXISTS; | ||
| 5257 | 5253 | ||
| 5258 | if (new) { | 5254 | if (new) { |
| 5259 | bc_array_init(&data.v, var); | 5255 | bc_array_init(&data.v, var); |
| @@ -6465,20 +6461,20 @@ static void bc_program_pushGlobal(char inst) | |||
| 6465 | 6461 | ||
| 6466 | static void bc_program_addFunc(char *name, size_t *idx) | 6462 | static void bc_program_addFunc(char *name, size_t *idx) |
| 6467 | { | 6463 | { |
| 6468 | BcStatus s; | ||
| 6469 | BcId entry, *entry_ptr; | 6464 | BcId entry, *entry_ptr; |
| 6470 | BcFunc f; | 6465 | BcFunc f; |
| 6466 | int inserted; | ||
| 6471 | 6467 | ||
| 6472 | entry.name = name; | 6468 | entry.name = name; |
| 6473 | entry.idx = G.prog.fns.len; | 6469 | entry.idx = G.prog.fns.len; |
| 6474 | 6470 | ||
| 6475 | s = bc_map_insert(&G.prog.fn_map, &entry, idx); | 6471 | inserted = bc_map_insert(&G.prog.fn_map, &entry, idx); |
| 6476 | if (s) free(name); | 6472 | if (!inserted) free(name); |
| 6477 | 6473 | ||
| 6478 | entry_ptr = bc_vec_item(&G.prog.fn_map, *idx); | 6474 | entry_ptr = bc_vec_item(&G.prog.fn_map, *idx); |
| 6479 | *idx = entry_ptr->idx; | 6475 | *idx = entry_ptr->idx; |
| 6480 | 6476 | ||
| 6481 | if (s == BC_STATUS_VEC_ITEM_EXISTS) { | 6477 | if (!inserted) { |
| 6482 | 6478 | ||
| 6483 | BcFunc *func = bc_vec_item(&G.prog.fns, entry_ptr->idx); | 6479 | BcFunc *func = bc_vec_item(&G.prog.fns, entry_ptr->idx); |
| 6484 | 6480 | ||
| @@ -6850,7 +6846,7 @@ static void bc_vm_info(void) | |||
| 6850 | 6846 | ||
| 6851 | static BcStatus bc_vm_error(BcStatus s, const char *file, size_t line) | 6847 | static BcStatus bc_vm_error(BcStatus s, const char *file, size_t line) |
| 6852 | { | 6848 | { |
| 6853 | if (!s || s > BC_STATUS_VEC_ITEM_EXISTS) return s; | 6849 | if (!s || s > BC_STATUS_BEFORE_POSIX) return s; |
| 6854 | 6850 | ||
| 6855 | fprintf(stderr, bc_err_fmt, bc_err_msgs[s]); | 6851 | fprintf(stderr, bc_err_fmt, bc_err_msgs[s]); |
| 6856 | fprintf(stderr, " %s", file); | 6852 | fprintf(stderr, " %s", file); |
