aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2020-03-25 18:20:31 -0700
committerPaul Eggert2020-03-25 18:38:07 -0700
commit98546d9c823db544b62bdba0bb388816ea6dd342 (patch)
treefe46e55c6146b8211ae08a2894bdde892691527a /src
parente4b6151ff119f36c64d3653b56f761fcdfe47fd3 (diff)
downloademacs-98546d9c823db544b62bdba0bb388816ea6dd342.tar.gz
emacs-98546d9c823db544b62bdba0bb388816ea6dd342.zip
Fix integer overflow in internal_self_insert
* src/cmds.c (internal_self_insert): Avoid undefined behavior on integer overflow by using saturated add.
Diffstat (limited to 'src')
-rw-r--r--src/cmds.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/cmds.c b/src/cmds.c
index 5b98a09fda9..c342cd88bd8 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -451,7 +451,10 @@ internal_self_insert (int c, EMACS_INT n)
451 string = concat2 (string, tem); 451 string = concat2 (string, tem);
452 } 452 }
453 453
454 replace_range (PT, PT + chars_to_delete, string, 1, 1, 1, 0); 454 ptrdiff_t to;
455 if (INT_ADD_WRAPV (PT, chars_to_delete, &to))
456 to = PTRDIFF_MAX;
457 replace_range (PT, to, string, 1, 1, 1, 0);
455 Fforward_char (make_fixnum (n)); 458 Fforward_char (make_fixnum (n));
456 } 459 }
457 else if (n > 1) 460 else if (n > 1)