[Toybox] [PATCH] Fix bug in 'xxd' for upper-case characters

Zach van Rijn me at zv.io
Sun May 6 15:01:48 PDT 2018


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-bug-in-xxd-causing-incorrect-translation-for-upp.patch
Type: text/x-patch
Size: 742 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20180506/0113cf97/attachment-0002.bin>


More information about the Toybox mailing list