From 9d3f3eb013f0a32d01e20b280a9f2a3c36a7ba00 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Sat, 14 Aug 2021 20:02:47 +0200 Subject: [PATCH] ENHANCED: format_string domain error for invalid radix in format string This addresses #1024. Example: ?- format("hello ~0r!", [12]). %@ caught: error(domain_error(format_string,"~0r"),format_//2) --- src/lib/format.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/format.pl b/src/lib/format.pl index ad9d40f7..f5bb0b05 100644 --- a/src/lib/format.pl +++ b/src/lib/format.pl @@ -344,12 +344,16 @@ pow10(D, N0-Pow0, N-Pow) :- N is N0 + D*10^Pow0, Pow is Pow0 + 1. +radix_error(lowercase, R) --> format_("~~~dr", [R]). +radix_error(uppercase, R) --> format_("~~~dR", [R]). + integer_to_radix(I0, R, Which, Cs) :- I is I0, % evaluate compound expression must_be(integer, I), must_be(integer, R), ( \+ between(2, 36, R) -> - domain_error(radix, R, format_//2) + phrase(radix_error(Which,R), Es), + domain_error(format_string, Es, format_//2) ; true ), digits(Which, Ds), -- 2.54.0