[libcamera-devel,01/10] cam: options: Rename optional arg to prevent aliasing
diff mbox series

Message ID 20201013151241.3557005-2-kieran.bingham@ideasonboard.com
State Superseded
Headers show
Series
  • Shadowed Variables
Related show

Commit Message

Kieran Bingham Oct. 13, 2020, 3:12 p.m. UTC
The parseValue function is given the optarg directly from the getopt
library, but the function retains the same name.

This causes an alias of the global optarg variable to be present in the
parseValue function. While this is not harmful, rename it to work
towards disabling aliases variables.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/cam/options.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Laurent Pinchart Oct. 13, 2020, 6:41 p.m. UTC | #1
Hi Kieran,

Thank you for the patch.

On Tue, Oct 13, 2020 at 04:12:32PM +0100, Kieran Bingham wrote:
> The parseValue function is given the optarg directly from the getopt
> library, but the function retains the same name.
> 
> This causes an alias of the global optarg variable to be present in the
> parseValue function. While this is not harmful, rename it to work
> towards disabling aliases variables.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  src/cam/options.cpp | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/src/cam/options.cpp b/src/cam/options.cpp
> index 358507eabf89..417c3ab49bc9 100644
> --- a/src/cam/options.cpp
> +++ b/src/cam/options.cpp
> @@ -77,7 +77,7 @@ void OptionsBase<T>::invalidate()
>  
>  template<typename T>
>  bool OptionsBase<T>::parseValue(const T &opt, const Option &option,
> -				const char *optarg)
> +				const char *arg)
>  {
>  	OptionValue value;
>  
> @@ -88,9 +88,9 @@ bool OptionsBase<T>::parseValue(const T &opt, const Option &option,
>  	case OptionInteger:
>  		unsigned int integer;
>  
> -		if (optarg) {
> +		if (arg) {
>  			char *endptr;
> -			integer = strtoul(optarg, &endptr, 0);
> +			integer = strtoul(arg, &endptr, 0);
>  			if (*endptr != '\0')
>  				return false;
>  		} else {
> @@ -101,12 +101,12 @@ bool OptionsBase<T>::parseValue(const T &opt, const Option &option,
>  		break;
>  
>  	case OptionString:
> -		value = OptionValue(optarg ? optarg : "");
> +		value = OptionValue(arg ? arg : "");
>  		break;
>  
>  	case OptionKeyValue:
>  		KeyValueParser *kvParser = option.keyValueParser;
> -		KeyValueParser::Options keyValues = kvParser->parse(optarg);
> +		KeyValueParser::Options keyValues = kvParser->parse(arg);
>  		if (!keyValues.valid())
>  			return false;
>
Laurent Pinchart Oct. 13, 2020, 6:42 p.m. UTC | #2
On Tue, Oct 13, 2020 at 09:41:56PM +0300, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Tue, Oct 13, 2020 at 04:12:32PM +0100, Kieran Bingham wrote:
> > The parseValue function is given the optarg directly from the getopt
> > library, but the function retains the same name.
> > 
> > This causes an alias of the global optarg variable to be present in the
> > parseValue function. While this is not harmful, rename it to work
> > towards disabling aliases variables.
> > 
> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

and

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

:-)

> > ---
> >  src/cam/options.cpp | 10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> > 
> > diff --git a/src/cam/options.cpp b/src/cam/options.cpp
> > index 358507eabf89..417c3ab49bc9 100644
> > --- a/src/cam/options.cpp
> > +++ b/src/cam/options.cpp
> > @@ -77,7 +77,7 @@ void OptionsBase<T>::invalidate()
> >  
> >  template<typename T>
> >  bool OptionsBase<T>::parseValue(const T &opt, const Option &option,
> > -				const char *optarg)
> > +				const char *arg)
> >  {
> >  	OptionValue value;
> >  
> > @@ -88,9 +88,9 @@ bool OptionsBase<T>::parseValue(const T &opt, const Option &option,
> >  	case OptionInteger:
> >  		unsigned int integer;
> >  
> > -		if (optarg) {
> > +		if (arg) {
> >  			char *endptr;
> > -			integer = strtoul(optarg, &endptr, 0);
> > +			integer = strtoul(arg, &endptr, 0);
> >  			if (*endptr != '\0')
> >  				return false;
> >  		} else {
> > @@ -101,12 +101,12 @@ bool OptionsBase<T>::parseValue(const T &opt, const Option &option,
> >  		break;
> >  
> >  	case OptionString:
> > -		value = OptionValue(optarg ? optarg : "");
> > +		value = OptionValue(arg ? arg : "");
> >  		break;
> >  
> >  	case OptionKeyValue:
> >  		KeyValueParser *kvParser = option.keyValueParser;
> > -		KeyValueParser::Options keyValues = kvParser->parse(optarg);
> > +		KeyValueParser::Options keyValues = kvParser->parse(arg);
> >  		if (!keyValues.valid())
> >  			return false;
> >
Niklas Söderlund Oct. 14, 2020, 12:18 p.m. UTC | #3
Hi Kieran,

On 2020-10-13 16:12:32 +0100, Kieran Bingham wrote:
> The parseValue function is given the optarg directly from the getopt
> library, but the function retains the same name.
> 
> This causes an alias of the global optarg variable to be present in the
> parseValue function. While this is not harmful, rename it to work
> towards disabling aliases variables.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  src/cam/options.cpp | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/src/cam/options.cpp b/src/cam/options.cpp
> index 358507eabf89..417c3ab49bc9 100644
> --- a/src/cam/options.cpp
> +++ b/src/cam/options.cpp
> @@ -77,7 +77,7 @@ void OptionsBase<T>::invalidate()
>  
>  template<typename T>
>  bool OptionsBase<T>::parseValue(const T &opt, const Option &option,
> -				const char *optarg)
> +				const char *arg)
>  {
>  	OptionValue value;
>  
> @@ -88,9 +88,9 @@ bool OptionsBase<T>::parseValue(const T &opt, const Option &option,
>  	case OptionInteger:
>  		unsigned int integer;
>  
> -		if (optarg) {
> +		if (arg) {
>  			char *endptr;
> -			integer = strtoul(optarg, &endptr, 0);
> +			integer = strtoul(arg, &endptr, 0);
>  			if (*endptr != '\0')
>  				return false;
>  		} else {
> @@ -101,12 +101,12 @@ bool OptionsBase<T>::parseValue(const T &opt, const Option &option,
>  		break;
>  
>  	case OptionString:
> -		value = OptionValue(optarg ? optarg : "");
> +		value = OptionValue(arg ? arg : "");
>  		break;
>  
>  	case OptionKeyValue:
>  		KeyValueParser *kvParser = option.keyValueParser;
> -		KeyValueParser::Options keyValues = kvParser->parse(optarg);
> +		KeyValueParser::Options keyValues = kvParser->parse(arg);
>  		if (!keyValues.valid())
>  			return false;
>  
> -- 
> 2.25.1
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch
diff mbox series

diff --git a/src/cam/options.cpp b/src/cam/options.cpp
index 358507eabf89..417c3ab49bc9 100644
--- a/src/cam/options.cpp
+++ b/src/cam/options.cpp
@@ -77,7 +77,7 @@  void OptionsBase<T>::invalidate()
 
 template<typename T>
 bool OptionsBase<T>::parseValue(const T &opt, const Option &option,
-				const char *optarg)
+				const char *arg)
 {
 	OptionValue value;
 
@@ -88,9 +88,9 @@  bool OptionsBase<T>::parseValue(const T &opt, const Option &option,
 	case OptionInteger:
 		unsigned int integer;
 
-		if (optarg) {
+		if (arg) {
 			char *endptr;
-			integer = strtoul(optarg, &endptr, 0);
+			integer = strtoul(arg, &endptr, 0);
 			if (*endptr != '\0')
 				return false;
 		} else {
@@ -101,12 +101,12 @@  bool OptionsBase<T>::parseValue(const T &opt, const Option &option,
 		break;
 
 	case OptionString:
-		value = OptionValue(optarg ? optarg : "");
+		value = OptionValue(arg ? arg : "");
 		break;
 
 	case OptionKeyValue:
 		KeyValueParser *kvParser = option.keyValueParser;
-		KeyValueParser::Options keyValues = kvParser->parse(optarg);
+		KeyValueParser::Options keyValues = kvParser->parse(arg);
 		if (!keyValues.valid())
 			return false;