From 20077c1429915b2c223e4d179a033f2b1806872c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 5 Aug 2017 17:50:35 +0200 Subject: libbb: make trim() return pointer to terminating NUL function old new delta trim 80 90 +10 angle_address 56 50 -6 sysctl_main 282 273 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: +10/-15) Total: -5 bytes Signed-off-by: Denys Vlasenko --- procps/sysctl.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'procps/sysctl.c') diff --git a/procps/sysctl.c b/procps/sysctl.c index 619f4f1e4..ef1a1b99f 100644 --- a/procps/sysctl.c +++ b/procps/sysctl.c @@ -257,12 +257,16 @@ static int sysctl_handle_preload_file(const char *filename) parse_flags &= ~PARSE_EOL_COMMENTS; // NO (only first char) - comments are recognized even if not first char while (config_read(parser, token, 2, 2, "#=", parse_flags)) { char *tp; - trim(token[0]); + trim(token[1]); + tp = trim(token[0]); sysctl_dots_to_slashes(token[0]); - tp = xasprintf("%s=%s", token[0], token[1]); - sysctl_act_on_setting(tp); - free(tp); + /* ^^^converted in-place. tp still points to NUL */ + /* now, add "=TOKEN1" */ + *tp++ = '='; + overlapping_strcpy(tp, token[1]); + + sysctl_act_on_setting(token[0]); } if (ENABLE_FEATURE_CLEAN_UP) config_close(parser); -- cgit v1.2.3