Skip to content

Commit

Permalink
fix upper hex in user templates
Browse files Browse the repository at this point in the history
  • Loading branch information
gzm55 committed Sep 24, 2021
1 parent ce458e4 commit f12215b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions test_unishox2.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,24 @@ if (argv >= 2 && strcmp(args[1], "-t") == 0) {
if (argv > 2)
preset = atoi(args[2]);

// check template
{
char cbuf[128];
char dbuf[128];
char *hex = ":AAAAAA-bbbbbb";
const int len = strlen(hex);
const int clen = unishox2_compress_lines(hex, len, cbuf, USX_HCODES_DFLT, USX_HCODE_LENS_DFLT, USX_FREQ_SEQ_DFLT, (const char *[]){":FFFFFF", "-ffffff", 0, 0, 0} , NULL);
const int dlen = unishox2_decompress_lines(cbuf, clen, dbuf, USX_HCODES_DFLT, USX_HCODE_LENS_DFLT, USX_FREQ_SEQ_DFLT, (const char *[]){":FFFFFF", "-ffffff", 0, 0, 0} , NULL);
if (dlen != len) {
printf("Fail len (template): %d, %d:\n%s\n%s\n", len, dlen, hex, dbuf);
return 1;
}
if (strncmp(hex, dbuf, len)) {
printf("Fail cmp (template):\n%s\n%s\n", hex, dbuf);
return 0;
}
}

// Basic
if (!test_ushx_cd("Hello", preset)) return 1;
if (!test_ushx_cd("Hello World", preset)) return 1;
Expand Down
4 changes: 2 additions & 2 deletions unishox2.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ int decodeRepeat(const char *in, int len, char *out, int ol, int *bit_no, struct
char getHexChar(int nibble, int hex_type) {
if (nibble >= 0 && nibble <= 9)
return '0' + nibble;
else if (hex_type < 3)
else if (hex_type < USX_NIB_HEX_UPPER)
return 'a' + nibble - 10;
return 'A' + nibble - 10;
}
Expand Down Expand Up @@ -1061,7 +1061,7 @@ int unishox2_decompress_lines(const char *in, int len, char *out, const byte usx
}
do {
int nibble = (int) getNumFromBits(in, len, bit_no, 4);
out[ol++] = getHexChar(nibble, idx);
out[ol++] = getHexChar(nibble, idx < 3 ? USX_NIB_HEX_LOWER : USX_NIB_HEX_UPPER);
if ((idx == 2 || idx == 4) && (nibble_count == 25 || nibble_count == 21 || nibble_count == 17 || nibble_count == 13))
out[ol++] = '-';
bit_no += 4;
Expand Down

0 comments on commit f12215b

Please sign in to comment.