]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/util.c
Merge pull request #969 from pwpiwi/gcc10_fixes
[proxmark3-svn] / client / util.c
index 7e2304888c7021206bd2d7ff03096c068e99e37c..2058044802f6e19e50086bec871db7b56513c0e0 100644 (file)
@@ -11,6 +11,7 @@
 #include "util.h"
 
 #include <stdint.h>
+#include <inttypes.h>
 #include <string.h>
 #include <ctype.h>
 #include <stdlib.h>
@@ -49,7 +50,7 @@ int ukbhit(void)
        error += tcsetattr(STDIN_FILENO, TCSANOW, &Otty);             // reset attributes
   }
 
-  return ( error == 0 ? cnt : -1 );
+  return cnt;
 }
 
 char getch(void)
@@ -169,23 +170,22 @@ void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex
        const size_t min_str_len, const size_t spaces_between, bool uppercase) {
 
        char *tmp = (char *)buf;
-       size_t i;
-       memset(tmp, 0x00, hex_max_len);
 
-       int maxLen = ( hex_len > hex_max_len) ? hex_max_len : hex_len;
+       int maxLen = (hex_len > hex_max_len) ? hex_max_len : hex_len;
 
-       for (i = 0; i < maxLen; ++i, tmp += 2 + spaces_between) {
+       for (int i = 0; i < maxLen; ++i, tmp += 2 + spaces_between) {
                sprintf(tmp, (uppercase) ? "%02X" : "%02x", (unsigned int) hex_data[i]);
 
-               for (int j = 0; j < spaces_between; j++)
-                       sprintf(tmp + 2 + j, " ");
+               if (i != maxLen - 1)
+                       for (int j = 0; j < spaces_between; j++)
+                               sprintf(tmp + 2 + j, " ");
        }
 
-       i *= (2 + spaces_between);
-       int minStrLen = min_str_len > i ? min_str_len : 0;
+       size_t len = strlen(tmp);
+       int minStrLen = min_str_len > len ? min_str_len : 0;
        if (minStrLen > hex_max_len)
                minStrLen = hex_max_len;
-       for(; i < minStrLen; i++, tmp += 1)
+       for (int i = len; i < minStrLen; i++, tmp += 1)
                sprintf(tmp, " ");
 
        return;
@@ -573,7 +573,7 @@ int param_gethex_to_eol(const char *line, int paramnum, uint8_t * data, int maxd
                }
 
                if (strlen(buf) >= 2) {
-                       sscanf(buf, "%x", &temp);
+                       sscanf(buf, "%" SCNx32, &temp);
                        data[*datalen] = (uint8_t)(temp & 0xff);
                        *buf = 0;
                        (*datalen)++;
Impressum, Datenschutz