aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-07-20 17:51:31 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-07-20 17:51:31 +0200
commit1856740ec0b4ffd8f780c3cc1ef9b38c9fc1eead (patch)
tree113bab1bc4644f37e83e75044bf3c28291ae9781
parent83e434d5b56baccf617ebcc8a752959f7c4aacfc (diff)
downloadbusybox-w32-1856740ec0b4ffd8f780c3cc1ef9b38c9fc1eead.tar.gz
busybox-w32-1856740ec0b4ffd8f780c3cc1ef9b38c9fc1eead.tar.bz2
busybox-w32-1856740ec0b4ffd8f780c3cc1ef9b38c9fc1eead.zip
hush: better names for o_free_unsafe() / o_free(), no logic changes
o_free() made o_string NULL-initialized, o_free_unsafe() did not bother reinitializing (expected caller to not need it). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 559595d2e..2da288c15 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -2797,13 +2797,13 @@ static void o_reset_to_empty_unquoted(o_string *o)
2797 o->data[0] = '\0'; 2797 o->data[0] = '\0';
2798} 2798}
2799 2799
2800static void o_free(o_string *o) 2800static void o_free_and_set_NULL(o_string *o)
2801{ 2801{
2802 free(o->data); 2802 free(o->data);
2803 memset(o, 0, sizeof(*o)); 2803 memset(o, 0, sizeof(*o));
2804} 2804}
2805 2805
2806static ALWAYS_INLINE void o_free_unsafe(o_string *o) 2806static ALWAYS_INLINE void o_free(o_string *o)
2807{ 2807{
2808 free(o->data); 2808 free(o->data);
2809} 2809}
@@ -3852,7 +3852,7 @@ static const struct reserved_combo* reserved_word(struct parse_context *ctx)
3852 int len = old->as_string.length; 3852 int len = old->as_string.length;
3853 /* Concatenate halves */ 3853 /* Concatenate halves */
3854 o_addstr(&old->as_string, ctx->as_string.data); 3854 o_addstr(&old->as_string, ctx->as_string.data);
3855 o_free_unsafe(&ctx->as_string); 3855 o_free(&ctx->as_string);
3856 /* Find where leading keyword starts in first half */ 3856 /* Find where leading keyword starts in first half */
3857 str = old->as_string.data + len; 3857 str = old->as_string.data + len;
3858 if (str > old->as_string.data) 3858 if (str > old->as_string.data)
@@ -4263,7 +4263,7 @@ static char *fetch_till_str(o_string *as_string,
4263 } 4263 }
4264 } 4264 }
4265 if (ch == EOF) { 4265 if (ch == EOF) {
4266 o_free_unsafe(&heredoc); 4266 o_free(&heredoc);
4267 return NULL; 4267 return NULL;
4268 } 4268 }
4269 o_addchr(&heredoc, ch); 4269 o_addchr(&heredoc, ch);
@@ -5033,7 +5033,7 @@ static struct pipe *parse_stream(char **pstring,
5033 if (done_word(&ctx)) { 5033 if (done_word(&ctx)) {
5034 goto parse_error; 5034 goto parse_error;
5035 } 5035 }
5036 o_free(&ctx.word); 5036 o_free_and_set_NULL(&ctx.word);
5037 done_pipe(&ctx, PIPE_SEQ); 5037 done_pipe(&ctx, PIPE_SEQ);
5038 pi = ctx.list_head; 5038 pi = ctx.list_head;
5039 /* If we got nothing... */ 5039 /* If we got nothing... */
@@ -5050,7 +5050,7 @@ static struct pipe *parse_stream(char **pstring,
5050 if (pstring) 5050 if (pstring)
5051 *pstring = ctx.as_string.data; 5051 *pstring = ctx.as_string.data;
5052 else 5052 else
5053 o_free_unsafe(&ctx.as_string); 5053 o_free(&ctx.as_string);
5054#endif 5054#endif
5055 debug_leave(); 5055 debug_leave();
5056 debug_printf_parse("parse_stream return %p\n", pi); 5056 debug_printf_parse("parse_stream return %p\n", pi);
@@ -5284,13 +5284,13 @@ static struct pipe *parse_stream(char **pstring,
5284 if (!HAS_KEYWORDS 5284 if (!HAS_KEYWORDS
5285 IF_HAS_KEYWORDS(|| (ctx.ctx_res_w == RES_NONE && ctx.old_flag == 0)) 5285 IF_HAS_KEYWORDS(|| (ctx.ctx_res_w == RES_NONE && ctx.old_flag == 0))
5286 ) { 5286 ) {
5287 o_free(&ctx.word); 5287 o_free_and_set_NULL(&ctx.word);
5288#if !BB_MMU 5288#if !BB_MMU
5289 debug_printf_parse("as_string2 '%s'\n", ctx.as_string.data); 5289 debug_printf_parse("as_string2 '%s'\n", ctx.as_string.data);
5290 if (pstring) 5290 if (pstring)
5291 *pstring = ctx.as_string.data; 5291 *pstring = ctx.as_string.data;
5292 else 5292 else
5293 o_free_unsafe(&ctx.as_string); 5293 o_free(&ctx.as_string);
5294#endif 5294#endif
5295 if (ch != ';' && IS_NULL_PIPE(ctx.list_head)) { 5295 if (ch != ';' && IS_NULL_PIPE(ctx.list_head)) {
5296 /* Example: bare "{ }", "()" */ 5296 /* Example: bare "{ }", "()" */
@@ -5568,7 +5568,7 @@ static struct pipe *parse_stream(char **pstring,
5568 free_pipe_list(pctx->list_head); 5568 free_pipe_list(pctx->list_head);
5569 debug_printf_clean("freed list %p\n", pctx->list_head); 5569 debug_printf_clean("freed list %p\n", pctx->list_head);
5570#if !BB_MMU 5570#if !BB_MMU
5571 o_free_unsafe(&pctx->as_string); 5571 o_free(&pctx->as_string);
5572#endif 5572#endif
5573 IF_HAS_KEYWORDS(p2 = pctx->stack;) 5573 IF_HAS_KEYWORDS(p2 = pctx->stack;)
5574 if (pctx != &ctx) { 5574 if (pctx != &ctx) {
@@ -5577,7 +5577,7 @@ static struct pipe *parse_stream(char **pstring,
5577 IF_HAS_KEYWORDS(pctx = p2;) 5577 IF_HAS_KEYWORDS(pctx = p2;)
5578 } while (HAS_KEYWORDS && pctx); 5578 } while (HAS_KEYWORDS && pctx);
5579 5579
5580 o_free(&ctx.word); 5580 o_free_and_set_NULL(&ctx.word);
5581#if !BB_MMU 5581#if !BB_MMU
5582 if (pstring) 5582 if (pstring)
5583 *pstring = NULL; 5583 *pstring = NULL;
@@ -5751,7 +5751,7 @@ static char *encode_then_expand_string(const char *str)
5751 /*unbackslash:*/ 1 5751 /*unbackslash:*/ 1
5752 ); 5752 );
5753 //bb_error_msg("'%s' -> '%s'", dest.data, exp_str); 5753 //bb_error_msg("'%s' -> '%s'", dest.data, exp_str);
5754 o_free_unsafe(&dest); 5754 o_free(&dest);
5755 return exp_str; 5755 return exp_str;
5756} 5756}
5757 5757
@@ -5868,7 +5868,7 @@ static char *encode_then_expand_vararg(const char *str, int handle_squotes, int
5868 ); 5868 );
5869 ret: 5869 ret:
5870 debug_printf_parse("expand: '%s' -> '%s'\n", dest.data, exp_str); 5870 debug_printf_parse("expand: '%s' -> '%s'\n", dest.data, exp_str);
5871 o_free_unsafe(&dest); 5871 o_free(&dest);
5872 return exp_str; 5872 return exp_str;
5873} 5873}
5874 5874
@@ -5916,7 +5916,7 @@ static int encode_then_append_var_plusminus(o_string *output, int n,
5916 */ 5916 */
5917 if (dest.data) { 5917 if (dest.data) {
5918 n = expand_vars_to_list(output, n, dest.data); 5918 n = expand_vars_to_list(output, n, dest.data);
5919 o_free(&dest); 5919 o_free_and_set_NULL(&dest);
5920 o_addchr(output, '\0'); 5920 o_addchr(output, '\0');
5921 n = o_save_ptr(output, n); /* create next word */ 5921 n = o_save_ptr(output, n); /* create next word */
5922 } else 5922 } else
@@ -6006,7 +6006,7 @@ static int encode_then_append_var_plusminus(o_string *output, int n,
6006 n = expand_vars_to_list(output, n, dest.data); 6006 n = expand_vars_to_list(output, n, dest.data);
6007 } 6007 }
6008 ret: 6008 ret:
6009 o_free_unsafe(&dest); 6009 o_free(&dest);
6010 return n; 6010 return n;
6011} 6011}
6012 6012
@@ -6588,7 +6588,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
6588 G.expand_exitcode = G.last_exitcode; 6588 G.expand_exitcode = G.last_exitcode;
6589 debug_printf_subst("SUBST RES:%d '%s'\n", G.last_exitcode, subst_result.data); 6589 debug_printf_subst("SUBST RES:%d '%s'\n", G.last_exitcode, subst_result.data);
6590 n = append_str_maybe_ifs_split(output, n, first_ch, subst_result.data); 6590 n = append_str_maybe_ifs_split(output, n, first_ch, subst_result.data);
6591 o_free_unsafe(&subst_result); 6591 o_free(&subst_result);
6592 break; 6592 break;
6593 } 6593 }
6594#endif 6594#endif
@@ -6631,7 +6631,8 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
6631 */ 6631 */
6632 o_addstr(output, arg); 6632 o_addstr(output, arg);
6633 debug_print_list("expand_vars_to_list[b]", output, n); 6633 debug_print_list("expand_vars_to_list[b]", output, n);
6634 } else if (output->length == o_get_last_ptr(output, n) /* expansion is empty */ 6634 } else
6635 if (output->length == o_get_last_ptr(output, n) /* expansion is empty */
6635 && !(cant_be_null & 0x80) /* and all vars were not quoted */ 6636 && !(cant_be_null & 0x80) /* and all vars were not quoted */
6636 && !output->has_quoted_part 6637 && !output->has_quoted_part
6637 ) { 6638 ) {