From fcf9683ed539fe4ecd926349a1cae3dc84378afa Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Fri, 28 Aug 1998 12:22:39 +0000 Subject: [PATCH] (Fposition_bytes): If the arg POSITION is out of range, return nil. (Fbyte_to_position): If the arg BYTEPOS is out of range, return nil. --- src/editfns.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/editfns.c b/src/editfns.c index 51b62c4baf..0be7c4a702 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -490,20 +490,26 @@ See also `gap-position'.") } DEFUN ("position-bytes", Fposition_bytes, Sposition_bytes, 1, 1, 0, - "Return the byte position for character position POSITION.") + "Return the byte position for character position POSITION.\n\ +If POSITION is out of range, the value is nil.") (position) Lisp_Object position; { CHECK_NUMBER_COERCE_MARKER (position, 1); + if (XINT (position) < BEG || XINT (position) > Z) + return Qnil; return make_number (CHAR_TO_BYTE (XINT (position))); } DEFUN ("byte-to-position", Fbyte_to_position, Sbyte_to_position, 1, 1, 0, - "Return the character position for byte position BYTEPOS.") + "Return the character position for byte position BYTEPOS.\n\ +If BYTEPOS is out of range, the value is nil.") (bytepos) Lisp_Object bytepos; { CHECK_NUMBER (bytepos, 1); + if (XINT (bytepos) < BEG_BYTE || XINT (bytepos) > Z_BYTE) + return Qnil; return make_number (BYTE_TO_CHAR (XINT (bytepos))); } -- 2.20.1