commit d14fc6b75f128ed538c123ec79bd3d955ca9bf70 (HEAD, refs/remotes/origin/master) Author: Pip Cet Date: Wed May 28 14:11:07 2025 +0000 Fix unsafe SDATA usage in print.c (bug#78590) * src/print.c (print_string_1): Renamed from 'print_string', with an extra argument to disable nonascii escaping. (print_string): New function. (print_object): Use 'print_string_1', not 'strout'. diff --git a/src/print.c b/src/print.c index b17ec337f70..b6ee89478c7 100644 --- a/src/print.c +++ b/src/print.c @@ -469,18 +469,18 @@ strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte, because printing one char can relocate. */ static void -print_string (Lisp_Object string, Lisp_Object printcharfun) +print_string_1 (Lisp_Object string, Lisp_Object printcharfun, bool escape_nonascii) { if (EQ (printcharfun, Qt) || NILP (printcharfun)) { ptrdiff_t chars; - if (print_escape_nonascii) + if (escape_nonascii) string = string_escape_byte8 (string); if (STRING_MULTIBYTE (string)) chars = SCHARS (string); - else if (! print_escape_nonascii + else if (! escape_nonascii && (EQ (printcharfun, Qt) ? ! NILP (BVAR (&buffer_defaults, enable_multibyte_characters)) : ! NILP (BVAR (current_buffer, enable_multibyte_characters)))) @@ -543,6 +543,12 @@ print_string (Lisp_Object string, Lisp_Object printcharfun) } } } + +static void +print_string (Lisp_Object string, Lisp_Object printcharfun) +{ + print_string_1 (string, printcharfun, print_escape_nonascii); +} DEFUN ("write-char", Fwrite_char, Swrite_char, 1, 2, 0, doc: /* Output character CHARACTER to stream PRINTCHARFUN. @@ -2282,7 +2288,7 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) } else if (STRINGP (num)) { - strout (SSDATA (num), SCHARS (num), SBYTES (num), printcharfun); + print_string_1 (num, printcharfun, false); goto next_obj; } } diff --git a/test/src/print-tests.el b/test/src/print-tests.el index af57311135b..036248fd091 100644 --- a/test/src/print-tests.el +++ b/test/src/print-tests.el @@ -540,5 +540,23 @@ otherwise, use a different charset." (should (eq callback-buffer buffer)) (should (equal str "tata")))) +(ert-deftest test-print-number-realloc () + ;; Test for bug#78590. Note that this may in rare cases crash unfixed + ;; Emacs versions. + (let ((print-circle t) + (print-number-table (make-hash-table)) + (print-continuous-numbering t) + (str "yy") + (outstr "")) + (garbage-collect) + (ignore (make-string 100 ?a)) + (puthash str (make-string 3 ?x) print-number-table) + (prin1 str + (lambda (c) + (setq outstr (concat outstr (string c))) + (garbage-collect) + (ignore (make-string 100 ?b)))) + (should (equal outstr "xxx")))) + (provide 'print-tests) ;;; print-tests.el ends here commit 295f73d23d337593959ec7d73ecbcfa61a732f0f Author: Juri Linkov Date: Wed May 28 20:15:21 2025 +0300 * lisp/isearch.el (search-within-boundaries): Optimize (bug#78520). For non-subregexp case, search for the first match and continue from its position. This avoids unnecessary scan for all text properties until the first match. When nothing is found, skip the entire body. diff --git a/lisp/isearch.el b/lisp/isearch.el index 6b759f4ad3e..68519b7a820 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -4610,9 +4610,7 @@ defaults to the value of `isearch-search-fun-default' when nil." (defun search-within-boundaries ( search-fun get-fun next-fun string &optional bound noerror count) (let* ((old (point)) - ;; Check if point is already on the property. - (beg (when (funcall get-fun old) old)) - end found (i 0) + beg end found skip (i 0) (subregexp (and isearch-regexp (save-match-data @@ -4622,18 +4620,33 @@ defaults to the value of `isearch-search-fun-default' when nil." (when (subregexp-context-p string (match-beginning 0)) ;; The ^/$ is not inside a char-range or escaped. (throw 'subregexp t)))))))) - ;; Otherwise, try to search for the next property. - (unless beg - (setq beg (funcall next-fun old)) - (when beg - (if (or (null bound) - (if isearch-forward - (< beg bound) - (> beg bound))) - (goto-char beg) - (setq beg nil)))) + + ;; Optimization for non-subregexp case to set the initial position + ;; on the first match assuming there is no need to check boundaries + ;; for a search string/regexp without anchors (bug#78520). + (unless subregexp + (save-match-data + (if (funcall (or search-fun (isearch-search-fun-default)) + string bound noerror count) + (goto-char (if isearch-forward (match-beginning 0) (match-end 0))) + (setq skip t)))) + + (unless skip + ;; Check if point is already on the property. + (setq beg (when (funcall get-fun (point)) (point))) + ;; Otherwise, try to search for the next property. + (unless beg + (setq beg (funcall next-fun (point))) + (when beg + (if (or (null bound) + (if isearch-forward + (< beg bound) + (> beg bound))) + (goto-char beg) + (setq beg nil))))) + ;; Non-nil `beg' means there are more properties. - (while (and beg (not found)) + (while (and beg (not found) (not skip)) ;; Search for the end of the current property. (setq end (funcall next-fun beg)) ;; Handle ^/$ specially by matching in a temporary buffer. commit 6279a9e8ef701c2eef8c198b7b26f235bb41f2b0 Author: Gerd Möllmann Date: Wed May 28 12:56:42 2025 +0200 Do child frame shortcut only on Cocoa (bug#78616) * src/nsterm.m ([EmacsWindow constrainFrameRect:toScreen:]): Return early for child frames only on Cocoa. diff --git a/src/nsterm.m b/src/nsterm.m index f822481e2e2..4884a060c3a 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -9801,11 +9801,11 @@ - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen /* Don't do anything for child frames because that leads to weird child frame placement in some cases involving Dock placement and Dock Hiding. */ +#ifdef NS_IMPL_COCOA struct frame *f = ((EmacsView *) [self delegate])->emacsframe; if (FRAME_PARENT_FRAME (f)) return frameRect; -#ifdef NS_IMPL_COCOA #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090 // If separate spaces is on, it is like each screen is independent. There is // no spanning of frames across screens.