aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias EngdegÄrd2025-07-25 21:53:37 +0200
committerMattias EngdegÄrd2025-07-25 21:54:59 +0200
commit33161e51e539eadeb11282c06df73a5d76afdff2 (patch)
tree8242f0dd59ef06486174d3600417c945062da6a6
parent50ffb29d0bbb92a7c6569c83d2e3e4868c4e867b (diff)
downloademacs-33161e51e539eadeb11282c06df73a5d76afdff2.tar.gz
emacs-33161e51e539eadeb11282c06df73a5d76afdff2.zip
Check for end-of-file when reading character escapes (bug#79097)
* src/lread.c (read_char_escape): Add check. * test/src/lread-tests.el (lread-char-escape-eof): New test.
-rw-r--r--src/lread.c2
-rw-r--r--test/src/lread-tests.el31
2 files changed, 33 insertions, 0 deletions
diff --git a/src/lread.c b/src/lread.c
index 287528ab32d..54b74b18782 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -3108,6 +3108,8 @@ read_char_escape (source_t *source, int next_char)
3108 chr = c; 3108 chr = c;
3109 break; 3109 break;
3110 } 3110 }
3111 if (chr < 0)
3112 end_of_file_error ();
3111 eassert (chr >= 0 && chr < (1 << CHARACTERBITS)); 3113 eassert (chr >= 0 && chr < (1 << CHARACTERBITS));
3112 3114
3113 /* Apply Control modifiers, using the rules: 3115 /* Apply Control modifiers, using the rules:
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el
index 02e3efcf06c..421c0c0ed4a 100644
--- a/test/src/lread-tests.el
+++ b/test/src/lread-tests.el
@@ -358,6 +358,37 @@ literals (Bug#20852)."
358 (should-error (read-from-string "?\\\n x")) 358 (should-error (read-from-string "?\\\n x"))
359 (should (equal (read-from-string "\"a\\\nb\"") '("ab" . 6)))) 359 (should (equal (read-from-string "\"a\\\nb\"") '("ab" . 6))))
360 360
361(ert-deftest lread-char-escape-eof ()
362 ;; Check that unfinished char escapes signal an error.
363 (should-error (read "?\\"))
364
365 (should-error (read "?\\^"))
366 (should-error (read "?\\C"))
367 (should-error (read "?\\M"))
368 (should-error (read "?\\S"))
369 (should-error (read "?\\H"))
370 (should-error (read "?\\A"))
371
372 (should-error (read "?\\C-"))
373 (should-error (read "?\\M-"))
374 (should-error (read "?\\S-"))
375 (should-error (read "?\\H-"))
376 (should-error (read "?\\A-"))
377 (should-error (read "?\\s-"))
378
379 (should-error (read "?\\C-\\"))
380 (should-error (read "?\\C-\\M"))
381 (should-error (read "?\\C-\\M-"))
382
383 (should-error (read "?\\x"))
384 (should-error (read "?\\u"))
385 (should-error (read "?\\u234"))
386 (should-error (read "?\\U"))
387 (should-error (read "?\\U0010010"))
388 (should-error (read "?\\N"))
389 (should-error (read "?\\N{"))
390 (should-error (read "?\\N{SPACE")))
391
361(ert-deftest lread-force-load-doc-strings () 392(ert-deftest lread-force-load-doc-strings ()
362 ;; Verify that lazy doc strings are loaded lazily by default, 393 ;; Verify that lazy doc strings are loaded lazily by default,
363 ;; but eagerly with `force-load-doc-strings' set. 394 ;; but eagerly with `force-load-doc-strings' set.