summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-05-20 09:09:03 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-05-20 09:09:03 +0200
commit85a26f0cfe681177d0ad396ef8e78ced4371e417 (patch)
tree4511be0235f488781e95dd15b6986934c7375c44
parentc848ade0146fe75284fda6ce297a30f79c62dbc3 (diff)
downloadorg-mode-85a26f0cfe681177d0ad396ef8e78ced4371e417.tar.gz
Fix "Stack overflow in regexp matcher" in `org-refresh-stats-properties'
* lisp/org.el (org-refresh-stats-properties): Simplify regexp. Small refactoring. Reported-by: Kevin Zettler <kevzettler@gmail.com> <http://permalink.gmane.org/gmane.emacs.orgmode/113555>
-rw-r--r--lisp/org.el29
1 files changed, 13 insertions, 16 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 1e28051..c8bab87 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9825,22 +9825,19 @@ sub-tree if optional argument INHERIT is non-nil."
(defun org-refresh-stats-properties ()
"Refresh stats text properties in the buffer."
- (let (stats)
- (org-with-silent-modifications
- (org-with-wide-buffer
- (goto-char (point-min))
- (while (re-search-forward
- (concat org-outline-regexp-bol ".*"
- "\\(?:\\[\\([0-9]+\\)%\\|\\([0-9]+\\)/\\([0-9]+\\)\\]\\)")
- nil t)
- (setq stats (cond ((equal (match-string 3) "0") 0)
- ((match-string 2)
- (/ (* (string-to-number (match-string 2)) 100)
- (string-to-number (match-string 3))))
- (t (string-to-number (match-string 1)))))
- (org-back-to-heading t)
- (put-text-property (point) (progn (org-end-of-subtree t t) (point))
- 'org-stats stats))))))
+ (org-with-silent-modifications
+ (org-with-point-at 1
+ (let ((regexp (concat org-outline-regexp-bol
+ ".*\\[\\([0-9]*\\)\\(?:%\\|/\\([0-9]*\\)\\)\\]")))
+ (while (re-search-forward regexp nil t)
+ (let* ((numerator (string-to-number (match-string 1)))
+ (denominator (and (match-end 2)
+ (string-to-number (match-string 2))))
+ (stats (cond ((not denominator) numerator) ;percent
+ ((= denominator 0) 0)
+ (t (/ (* numerator 100) denominator)))))
+ (put-text-property (point) (progn (org-end-of-subtree t t) (point))
+ 'org-stats stats)))))))
(defun org-refresh-effort-properties ()
"Refresh effort properties"