Check input of NTP conversion function

This commit is contained in:
Daniel - 2020-01-09 21:35:23 +01:00
parent 57107c0c75
commit df2464ce5b
No known key found for this signature in database
GPG Key ID: 1C7071A75BB72D64
1 changed files with 6 additions and 4 deletions

View File

@ -206,10 +206,12 @@ might depend on the coding system of the current buffer."
HIGH and LOW must both be 8 digit hex strings. If not given, HIGH and LOW must both be 8 digit hex strings. If not given,
FORMAT-STRING defaults to some ISO 8601-like format." FORMAT-STRING defaults to some ISO 8601-like format."
(interactive (cl-flet ((read-hex (prompt) (interactive (cl-flet ((read-hex (prompt)
(string-to-number (->> prompt (let ((input-proper (->> prompt
(read-string) (read-string)
(replace-regexp-in-string "[\n\t ]" "")) (replace-regexp-in-string "[\n\t ]" ""))))
16))) (if (not (string-match-p "[0-9a-fA-F]\\{8\\}" input-proper))
(user-error "Input invalid, must be an 8 digit hex string.")
(string-to-number input-proper 16)))))
(list (read-hex "High (hex): ") (list (read-hex "High (hex): ")
(read-hex "Low (hex): ")))) (read-hex "Low (hex): "))))
(let* ((high-seconds (- high 2208988800)) ; subtract seconds between 1900-01-01 and the epoch (let* ((high-seconds (- high 2208988800)) ; subtract seconds between 1900-01-01 and the epoch