This patch fixes what I imagine is a typo in 'xxd', quickly
verified by the following program:

$ cat xxd_bug.c
#include <stdio.h>

int dehex(char ch)
{
  if (ch >= '0' && ch <= '9') return ch - '0';
  if (ch >= 'a' && ch <= 'f') return ch - 'a' + 10;
  if (ch >= 'A' && ch <= 'F') return ch - 'a' + 10;
  return (ch == '\n') ? -2 : -1;
}

int main(int c, char **v)
{
  printf("%d\n", dehex(v[1][0]));
  return 0;
}

$ ./xxd_bug a
10
$ ./xxd_bug A
-22

After applying the patch, return values are identical.

ZV
From 955cb0114e3bfc7a53173425b57be8eec5bb42b1 Mon Sep 17 00:00:00 2001
From: Zach van Rijn <[email protected]>
Date: Sun, 6 May 2018 17:49:27 -0400
Subject: [PATCH] Fix bug in 'xxd' causing incorrect translation for upper-case
 characters.

---
 toys/other/xxd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/toys/other/xxd.c b/toys/other/xxd.c
index 6203d7a..80892fb 100644
--- a/toys/other/xxd.c
+++ b/toys/other/xxd.c
@@ -103,7 +103,7 @@ static int dehex(char ch)
 {
   if (ch >= '0' && ch <= '9') return ch - '0';
   if (ch >= 'a' && ch <= 'f') return ch - 'a' + 10;
-  if (ch >= 'A' && ch <= 'F') return ch - 'a' + 10;
+  if (ch >= 'A' && ch <= 'F') return ch - 'A' + 10;
   return (ch == '\n') ? -2 : -1;
 }
 
-- 
1.8.3.1

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to