]> cygwin.com Git - cygwin-apps/setup.git/commitdiff
Fix the reading and writing of the "extrakeys" user setting
authorKen Brown <kbrown@cornell.edu>
Mon, 27 Nov 2017 18:14:15 +0000 (13:14 -0500)
committerKen Brown <kbrown@cornell.edu>
Tue, 28 Nov 2017 13:41:01 +0000 (08:41 -0500)
ExtraKeysSetting::keybuffer is terminated by LF rather than NUL.  So
we have to replace NUL by LF after calling
UserSettings::get("extrakeys") in the ExtraKeysSetting constructor.
Otherwise the last saved key is discarded.  Also, bufsize has to be
set appropriately before the call to count_keys(), or else all saved
keys are discarded.

Similarly, the final LF in keybuffer has to be replaced by NUL in the
ExtraKeysSetting destructor before the call to
UserSettings::set("extrakeys", keybuffer).  Otherwise we get garbage
at the end of the "extrakeys" setting in setup.rc.

KeysSetting.cc

index a21c3c4f2b44f285bad947488735ddf3a324b328..ec8e4f90a7b75b3cb2937d642365bc6d6b71a13b 100644 (file)
@@ -36,7 +36,10 @@ ExtraKeysSetting::ExtraKeysSetting ():
   const char *p = UserSettings::instance().get ("extrakeys");
   if (p)
     {
+      bufsize = strlen (p) + 1;        // Include final NUL.
       keybuffer = strdup (p);
+      // Replace final NUL by LF.
+      keybuffer[bufsize - 1] = 0x0a;
       // Calling count_keys gets the count but also sizes the buffer
       // correctly, discarding any trailing non-LF-terminated data.
       bufsize = count_keys ();
@@ -46,7 +49,11 @@ ExtraKeysSetting::ExtraKeysSetting ():
 ExtraKeysSetting::~ExtraKeysSetting ()
 {
   if (keybuffer)
-    UserSettings::instance().set ("extrakeys", keybuffer);
+    {
+      // Replace final LF by NUL.
+      keybuffer[bufsize - 1] = '\0';
+      UserSettings::instance().set ("extrakeys", keybuffer);
+    }
 }
 
 void
This page took 0.034554 seconds and 5 git commands to generate.