iio: Do not accept multiple '.' in fixed point numbers
PATCH 1/3 iio: Do not accept multiple '.' in fixed point numbers
Currently when parsing a fix-point number we silently skip any additional '.' found in the string. E.g. '1.2.3.4' gets parsed as '1.234'. This patch disallows this and returns an error if more than one '.' is encountered.
--- drivers/iio/industrialio-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/industrialio-core.c +1 -1
@@ -449,7 +449,7 @@ static ssize_t iio_write_channel_info(struct device *dev,break ; else return -EINVAL; - }else if (*buf =='.' ) { + }else if (*buf =='.' && integer_part) { integer_part = false; }else {return -EINVAL ;
Signature · 1 line
1.7.10.4
PATCH 2/3 iio: Reject trailing garbage when parsing fixed point numbers
When parsing a fixed point number IIO stops parsing the string once it has reached the last requested decimal place. This means that the remainder of the string is silently accepted regardless, of whether it is part of a valid number or not. This patch modifies the code to scan the whole string and only accept valid numbers. Since fract_mult is 0 after the last decimal place any digit that may follows won't affect the result.
--- drivers/iio/industrialio-core.c | 2 -- 1 file changed, 2 deletions(-)
drivers/iio/industrialio-core.c +0 -2
@@ -440,8 +440,6 @@ static ssize_t iio_write_channel_info(struct device *dev, integer = integer*10 + *buf -'0' ; else { fract += fract_mult*(*buf -'0' ); -if (fract_mult ==1 ) -break ; fract_mult /=10 ; } }else if (*buf =='\n' ) {
Signature · 1 line
1.7.10.4
PATCH 3/3 iio: Accept a leading '+' sign when parsing fixed point numbers
In reply to Lars-Peter ClausenIf we encounter a leading '+' sign just skip over it.
--- drivers/iio/industrialio-core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/industrialio-core.c +2 -0
@@ -432,6 +432,8 @@ static ssize_t iio_write_channel_info(struct device *dev,if (buf[0 ] =='-' ) { negative = true; buf++; + }else if (buf[0 ] =='+' ) { + buf++; }while (*buf) {
Signature · 1 line
1.7.10.4
Jonathan Cameron
maintainerQuoted 5 lines · Lars-Peter Clausen
Currently when parsing a fix-point number we silently skip any additional '.' found in the string. E.g. '1.2.3.4' gets parsed as '1.234'. This patch disallows this and returns an error if more than one '.' is encountered.
Signed-off-by Lars-Peter Clausen <[email protected]>
Added to togreg branch of iio.git
Quoted 18 lines
--- drivers/iio/industrialio-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/industrialio-core.c +1
-1@@ -449,7 +449,7 @@ static ssize_t iio_write_channel_info(struct device *dev,break ; else return -EINVAL; - }else if (*buf =='.' ) { + }else if (*buf =='.' && integer_part) { integer_part = false; }else {return -EINVAL ;
Jonathan Cameron
maintainerRe: [PATCH 2/3] iio: Reject trailing garbage when parsing fixed point numbers
In reply to Lars-Peter ClausenQuoted 8 lines · Lars-Peter Clausen
When parsing a fixed point number IIO stops parsing the string once it has reached the last requested decimal place. This means that the remainder of the string is silently accepted regardless, of whether it is part of a valid number or not. This patch modifies the code to scan the whole string and only accept valid numbers. Since
fract_multis 0 after the last decimal place any digit that may follows won't affect the result.Signed-off-by Lars-Peter Clausen <[email protected]>
Nice little trick.
Added to togreg branch of iio.git
Quoted 18 lines
--- drivers/iio/industrialio-core.c | 2 -- 1 file changed, 2 deletions(-)drivers/iio/industrialio-core.c +0
-2@@ -440,8 +440,6 @@ static ssize_t iio_write_channel_info(struct device *dev, integer = integer*10 + *buf -'0' ; else { fract += fract_mult*(*buf -'0' ); -if (fract_mult ==1 ) -break ; fract_mult /=10 ; } }else if (*buf =='\n' ) {
Jonathan Cameron
maintainerRe: [PATCH 3/3] iio: Accept a leading '+' sign when parsing fixed point numbers
In reply to Lars-Peter ClausenQuoted 3 lines · Lars-Peter Clausen
If we encounter a leading '+' sign just skip over it.
Signed-off-by Lars-Peter Clausen <[email protected]>
Can't say I care either way on this, but it's helpful to you why not...
Added to togreg branch of iio.git
Quoted 18 lines
--- drivers/iio/industrialio-core.c | 2 ++ 1 file changed, 2 insertions(+)drivers/iio/industrialio-core.c +2
-0@@ -432,6 +432,8 @@ static ssize_t iio_write_channel_info(struct device *dev,if (buf[0 ] =='-' ) { negative = true; buf++; + }else if (buf[0 ] =='+' ) { + buf++; }while (*buf) {