Fix code review issues: infinite loop prevention and consistent return values

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-12 03:37:30 +00:00
parent 73f65e294b
commit a34c1ee625

16
tp.el
View File

@ -398,10 +398,10 @@ PROPERTIES should be a plist of property-value pairs."
(declare (indent defun)) (declare (indent defun))
(cond (cond
;; Called with just string and properties (no start/end) ;; Called with just string and properties (no start/end)
;; Detect by checking if first arg is not a number (not a start position)
((and (stringp object-or-string) ((and (stringp object-or-string)
(or (null args) (or (null args)
(symbolp (car args)) (not (numberp (car args)))))
(and (listp (car args)) (symbolp (caar args)))))
(let ((properties args)) (let ((properties args))
(when (listp (car-safe properties)) (when (listp (car-safe properties))
(setq properties (car properties))) (setq properties (car properties)))
@ -419,7 +419,8 @@ PROPERTIES should be a plist of property-value pairs."
(properties (cddr args))) (properties (cddr args)))
(when (listp (car-safe properties)) (when (listp (car-safe properties))
(setq properties (car properties))) (setq properties (car properties)))
(tp-put object start end properties))) (tp-put object start end properties)
object)) ; Always return the object
(t (error "Invalid arguments to tp-propertize")))) (t (error "Invalid arguments to tp-propertize"))))
(defun tp-layer-propertize (object layer &optional start end) (defun tp-layer-propertize (object layer &optional start end)
@ -451,7 +452,8 @@ Returns the modified object."
(fin (or end (if (stringp object) (fin (or end (if (stringp object)
(length object) (length object)
(with-current-buffer object (point-max)))))) (with-current-buffer object (point-max))))))
(tp-put object beg fin props))) (tp-put object beg fin props)
object)) ; Always return the object
(t (error "Invalid object type: %S" (type-of object))))) (t (error "Invalid object type: %S" (type-of object)))))
(error "Layer %S doesn't exist!" layer))) (error "Layer %S doesn't exist!" layer)))
@ -612,7 +614,8 @@ Returns:
(end (match-end 0))) (end (match-end 0)))
(when properties (when properties
(tp-put object beg end properties)) (tp-put object beg end properties))
(setq pos end))) ;; Advance by at least 1 to avoid infinite loop on empty match
(setq pos (max (1+ beg) end))))
object)) object))
;; Buffer or nil (current buffer) ;; Buffer or nil (current buffer)
(t (t
@ -675,7 +678,8 @@ Returns:
(end (match-end 0))) (end (match-end 0)))
(when properties (when properties
(tp-put object beg end properties)) (tp-put object beg end properties))
(setq pos end))) ;; Advance by at least 1 to avoid infinite loop on zero-width match
(setq pos (max (1+ beg) end))))
object)) object))
;; Buffer or nil (current buffer) ;; Buffer or nil (current buffer)
(t (t