]> gitweb.factorcode.org Git - factor.git/commitdiff
math.parser: require hex-string>bytes to have even digits
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 12 Feb 2024 18:42:08 +0000 (10:42 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 12 Feb 2024 18:42:08 +0000 (10:42 -0800)
core/math/parser/parser-tests.factor
core/math/parser/parser.factor

index 9e3b3d2159047e90134880ba2ef5378905afd140..13e4514c436d41906e8b027a93f56942030af623 100644 (file)
@@ -480,6 +480,7 @@ unit-test
 
 { "deadbeef" } [ B{ 222 173 190 239 } bytes>hex-string ] unit-test
 { B{ 222 173 190 239 } } [ "deADbeEF" hex-string>bytes ] unit-test
+[ "0" hex-string>bytes ] [ invalid-hex-string-length? ] must-fail-with
 
 {
     B{ 49 46 53 53 69 43 48 53 }
index 2e1d5a4b0f4dd3447665859e70d5587088e8ecd5..778c754981c151c02527627f753bc75a14bfedd7 100644 (file)
@@ -1019,8 +1019,10 @@ M: float >base
 
 : # ( n -- ) number>string % ; inline
 
+ERROR: invalid-hex-string-length n ;
+
 : hex-string>bytes ( hex-string -- bytes )
-    dup length 2/ <byte-array> [
+    dup length dup even? [ invalid-hex-string-length ] unless 2/ <byte-array> [
         [
             [ digit> ] 2dip over even? [
                 [ 16 * ] [ 2/ ] [ set-nth-unsafe ] tri*