From ba5833318b3168685b0349aa41f487422fcb62d5 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sat, 11 Aug 2018 14:42:09 +0200 Subject: [PATCH] conv: Fix taking out of range chars for hex values --- source/tanya/conv.d | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/source/tanya/conv.d b/source/tanya/conv.d index 561ccce..bce5401 100644 --- a/source/tanya/conv.d +++ b/source/tanya/conv.d @@ -308,11 +308,11 @@ do { digit = range.front - 'W'; } - else if (range.front >= 'A') + else if (range.front >= 'A' && range.front <= 'Z') { digit = range.front - '7'; } - else if (range.front >= '0') + else if (range.front >= '0' && range.front <= '9') { digit = range.front - '0'; } @@ -360,6 +360,15 @@ do return n; } +// ':' is not a hex value +@nogc nothrow pure @safe unittest +{ + string colon = ":"; + auto actual = readIntegral!ubyte(colon, 16); + assert(actual == 0); + assert(colon.length == 1); +} + // reads ubyte.max @nogc nothrow pure @safe unittest {