Skip to contentSkip to conversation

tools: iio: iio_generic_buffer: make num_loops signed

PATCH New Martin Kelly 1 participant 1 message Jan 11, 2019 IIO

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tools: iio: iio_generic_buffer: make num_loops signed

Currently, num_loops is unsigned, but it's set by strtoll, which returns a (signed) long long int. This could lead to overflow, and it also makes the check "num_loops < 0" always be false, since num_loops is unsigned. Setting num_loops to -1 to loop forever is almost working because num_loops is getting set to a very high number, but it's technically still incorrect.

Fix this issue by making num_loops signed. This also fixes an error found by Smatch.

Fixes 55dda0abcf9d ("tools: iio: iio_generic_buffer: allow continuous looping")

---
v2:
- No content change; added a Fixes tag.

 tools/iio/iio_generic_buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/iio/iio_generic_buffer.c +1 -1
index 3040830d7797..84545666a09c 100644
@@ -330,7 +330,7 @@ static const struct option longopts[] = {
 
 int main(int argc, char **argv)
 {
-	unsigned long long num_loops = 2;
+	long long num_loops = 2;
 	unsigned long timedelay = 1000000;
 	unsigned long buf_len = 128;
 
Signature · 1 line
2.20.1