[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Re: [PATCH 2/4] compare_string_array: code shrink
From: Denys Vlasenko <vda.linux () googlemail ! com>
Date: 2020-06-29 14:11:32
Message-ID: CAK1hOcO_DuhYtcGxXw_TBSi2g6_j0BGytNwrefOO0b7o3yGyfA () mail ! gmail ! com
[Download RAW message or body]
Applied, thanks!
On Thu, Jun 11, 2020 at 3:45 PM Martin Lewis <martin.lewis.x84@gmail.com> wrote:
>
> Code shrink and prevention of possible out of bounds access.
>
> function old new delta
> nth_string 36 26 -10
> ------------------------------------------------------------------------------
> (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-10) Total: -10 bytes
> text data bss dec hex filename
> 981342 16915 1872 1000129 f42c1 busybox_old
> 981332 16915 1872 1000119 f42b7 busybox_unstripped
>
> Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
> ---
> libbb/compare_string_array.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c
> index 01a9df0e2..a06e57d3d 100644
> --- a/libbb/compare_string_array.c
> +++ b/libbb/compare_string_array.c
> @@ -117,8 +117,11 @@ int FAST_FUNC index_in_substrings(const char *strings, const char *key)
> const char* FAST_FUNC nth_string(const char *strings, int n)
> {
> while (n) {
> - n--;
> - strings += strlen(strings) + 1;
> + if (*strings++ == '\0') {
> + if (*strings == '\0') /* reached end of strings */
> + break;
> + n--;
> + }
> }
> return strings;
> }
> --
> 2.11.0
>
> _______________________________________________
> busybox mailing list
> busybox@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic