commit 68fced93379aa402259fff09064d0aab579e3f59
Author: Hiroo HAYASHI <24754036+hirooih@users.noreply.github.com>
Date:   Sun Jun 9 11:03:57 2024 +0900

    fix invert_case_line() in examples/manexamp.c
    
    - fix bug invert_case_line() causes segfault with negative arguments.
    - make cursor behavior similar to other readline commands.
    
    Signed-off-by: Hiroo HAYASHI <24754036+hirooih@users.noreply.github.com>

diff --git a/examples/manexamp.c b/examples/manexamp.c
index baf4d41..b0ce846 100644
--- a/examples/manexamp.c
+++ b/examples/manexamp.c
@@ -33,7 +33,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <errno.h>
-   
+
 #include <locale.h>
 
 #ifndef errno
@@ -92,16 +92,18 @@ invert_case_line (int count, int key)
   int start, end;
   int direction;
 
-  start = rl_point;
-
   if (count < 0)
     {
+      start = rl_point - 1;
       direction = -1;
       count = -count;
     }
   else
-    direction = 1;
-      
+    {
+      start = rl_point;
+      direction = 1;
+    }
+
   /* Find the end of the range to modify. */
   end = start + (count * direction);
 
@@ -133,9 +135,11 @@ invert_case_line (int count, int key)
 	rl_line_buffer[start] = _rl_to_upper (rl_line_buffer[start]);
     }
 
-  /* Move point to on top of the last character changed. */
-  rl_point = end - direction;
-  return 0;
+    /* For positive arguments, moves the point to the right of the last changed
+       character. For negative arguments, moves the point above the last changed
+       character. */
+    rl_point = direction == 1 ? end : end + 1;
+    return 0;
 }
 
 int main(int c, char **v) {
