From: Andrew Lunn <andrew@lunn.ch>
To: Jesse Brandeburg <jesse.brandeburg@intel.com>
Cc: mkubecek@suse.cz, netdev@vger.kernel.org
Subject: Re: [PATCH ethtool v2 06/13] ethtool: fix uninitialized local variable use
Date: Thu, 8 Dec 2022 03:06:39 +0100 [thread overview]
Message-ID: <Y5FGr9Tgmta0Qwpn@lunn.ch> (raw)
In-Reply-To: <20221208011122.2343363-7-jesse.brandeburg@intel.com>
On Wed, Dec 07, 2022 at 05:11:15PM -0800, Jesse Brandeburg wrote:
> '$ scan-build make' reports:
>
> netlink/parser.c:252:25: warning: The left operand of '*' is a garbage value [core.UndefinedBinaryOperatorResult]
> cm = (uint32_t)(meters * 100 + 0.5);
> ~~~~~~ ^
>
> This is a little more complicated than it seems, but for some
> unexplained reason, parse_float always returns integers but was declared
> to return a float.
Looks like i got that wrong. Duh!
> This is confusing at best. In the case of the error
> above, parse_float could conceivably return without initializing it's
> output variable, and because the function return variable was declared
> as float but downgraded to an int via assignment (-Wconversion anyone?)
> upon the return, the return value could be ignored.
>
> To fix the bug above, declare an initial value for meters, and make sure
> that parse_float() always returns an integer value.
>
> It would probably be even more ideal if parse_float always initialized
> it's output variables before even checking for input errors, but that's
> for some future day.
It is also following the pattern of other parse_foo functions. None of
them set the result in case of errors.
>
> CC: Andrew Lunn <andrew@lunn.ch>
> Fixes: 9561db9b76f4 ("Add cable test TDR support")
> Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
> ---
> netlink/parser.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/netlink/parser.c b/netlink/parser.c
> index f982f229a040..70f451008eb4 100644
> --- a/netlink/parser.c
> +++ b/netlink/parser.c
> @@ -54,8 +54,7 @@ static bool __prefix_0x(const char *p)
> return p[0] == '0' && (p[1] == 'x' || p[1] == 'X');
> }
>
> -static float parse_float(const char *arg, float *result, float min,
> - float max)
> +static int parse_float(const char *arg, float *result, float min, float max)
> {
> char *endptr;
> float val;
> @@ -237,7 +236,7 @@ int nl_parse_direct_m2cm(struct nl_context *nlctx, uint16_t type,
> struct nl_msg_buff *msgbuff, void *dest)
> {
> const char *arg = *nlctx->argp;
> - float meters;
> + float meters = 0;
> uint32_t cm;
> int ret;
Should this actually be 0.0? Otherwise if -Wconversion gets turned on,
you have an int being converted to a float?
Anyway:
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
next prev parent reply other threads:[~2022-12-08 2:06 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-08 1:11 [PATCH ethtool v2 00/13] ethtool: clean up and fix Jesse Brandeburg
2022-12-08 1:11 ` [PATCH ethtool v2 01/13] ethtool: convert boilerplate licenses to SPDX Jesse Brandeburg
2022-12-08 8:17 ` Michal Kubecek
2022-12-08 1:11 ` [PATCH ethtool v2 02/13] ethtool: fix trivial issue in allocation Jesse Brandeburg
2022-12-08 8:26 ` Michal Kubecek
2022-12-08 1:11 ` [PATCH ethtool v2 03/13] ethtool: disallow passing null to find_option Jesse Brandeburg
2022-12-08 9:14 ` Michal Kubecek
2022-12-08 1:11 ` [PATCH ethtool v2 04/13] ethtool: commonize power related strings Jesse Brandeburg
2022-12-08 10:25 ` Michal Kubecek
2022-12-08 1:11 ` [PATCH ethtool v2 05/13] ethtool: fix extra warnings Jesse Brandeburg
2022-12-08 10:43 ` Michal Kubecek
2022-12-08 1:11 ` [PATCH ethtool v2 06/13] ethtool: fix uninitialized local variable use Jesse Brandeburg
2022-12-08 2:06 ` Andrew Lunn [this message]
2022-12-08 1:11 ` [PATCH ethtool v2 07/13] ethtool: avoid null pointer dereference Jesse Brandeburg
2022-12-08 6:23 ` Michal Kubecek
2022-12-09 17:36 ` Jesse Brandeburg
2022-12-09 18:06 ` Michal Kubecek
2022-12-08 1:11 ` [PATCH ethtool v2 08/13] ethtool: fix runtime errors found by sanitizers Jesse Brandeburg
2022-12-08 6:34 ` Michal Kubecek
2022-12-09 17:42 ` Jesse Brandeburg
2022-12-09 18:09 ` Michal Kubecek
2022-12-09 22:09 ` Jesse Brandeburg
2022-12-08 1:11 ` [PATCH ethtool v2 09/13] ethtool: merge uapi changes to implement BIT and friends Jesse Brandeburg
2022-12-08 6:44 ` Michal Kubecek
2022-12-09 17:53 ` Jesse Brandeburg
2022-12-08 1:11 ` [PATCH ethtool v2 10/13] ethtool: refactor bit shifts to use BIT and BIT_ULL Jesse Brandeburg
2022-12-08 1:11 ` [PATCH ethtool v2 11/13] ethtool: fix missing free of memory after failure Jesse Brandeburg
2022-12-08 10:52 ` Michal Kubecek
2022-12-08 1:11 ` [PATCH ethtool v2 12/13] ethtool: fix leak of memory after realloc Jesse Brandeburg
2022-12-08 11:30 ` Michal Kubecek
2022-12-08 1:11 ` [PATCH ethtool v2 13/13] ethtool: fix bug and use standard string parsing Jesse Brandeburg
2022-12-08 11:48 ` Michal Kubecek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y5FGr9Tgmta0Qwpn@lunn.ch \
--to=andrew@lunn.ch \
--cc=jesse.brandeburg@intel.com \
--cc=mkubecek@suse.cz \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.