Browse Source

Bugfix: bitfury: Use long long and llabs to avoid under/over flows misbehaving

Luke Dashjr 11 years ago
parent
commit
e6d15c8d0e
1 changed files with 3 additions and 3 deletions
  1. 3 3
      libbitfury.c

+ 3 - 3
libbitfury.c

@@ -241,7 +241,7 @@ int libbitfury_detect_chip(struct spi_port *port, int chip_n) {
 	int i;
 	int i;
 	uint32_t newbuf[17] = {0}, oldbuf[17] = {0};
 	uint32_t newbuf[17] = {0}, oldbuf[17] = {0};
 	uint32_t ocounter;
 	uint32_t ocounter;
-	long odiff = 0;
+	long long odiff = 0;
 
 
 	memset(newbuf, 0, 17 * 4);
 	memset(newbuf, 0, 17 * 4);
 	memset(oldbuf, 0, 17 * 4);
 	memset(oldbuf, 0, 17 * 4);
@@ -274,9 +274,9 @@ int libbitfury_detect_chip(struct spi_port *port, int chip_n) {
 
 
 		counter = libbitfury_get_counter(newbuf, oldbuf);
 		counter = libbitfury_get_counter(newbuf, oldbuf);
 		if (ocounter) {
 		if (ocounter) {
-			uint32_t cdiff = libbitfury_c_diff(ocounter, counter);
+			long long cdiff = libbitfury_c_diff(ocounter, counter);
 
 
-			if (abs(odiff - cdiff) < 5000)
+			if (llabs(odiff - cdiff) < 5000)
 				return 1;
 				return 1;
 			odiff = cdiff;
 			odiff = cdiff;
 		}
 		}