From: Ken Brown <kbrown@cornell.edu>
To: cygwin-apps@cygwin.com
Subject: [PATCH setup 1/3] Fix the reading and writing of the "extrakeys" user setting
Date: Tue, 28 Nov 2017 14:56:00 -0000 [thread overview]
Message-ID: <20171128145605.12860-2-kbrown@cornell.edu> (raw)
In-Reply-To: <20171128145605.12860-1-kbrown@cornell.edu>
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 | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/KeysSetting.cc b/KeysSetting.cc
index a21c3c4..ec8e4f9 100644
--- a/KeysSetting.cc
+++ b/KeysSetting.cc
@@ -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
--
2.15.0
next prev parent reply other threads:[~2017-11-28 14:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-28 14:56 [PATCH setup 0/3] Fix "extrakeys" issues Ken Brown
2017-11-28 14:56 ` [PATCH setup 3/3] Remove references to "last-extrakeys" Ken Brown
2017-11-28 14:56 ` Ken Brown [this message]
2017-11-28 14:56 ` [PATCH setup 2/3] Change the interpretation of '#' in setup.rc Ken Brown
2017-11-28 15:28 ` [PATCH setup 0/3] Fix "extrakeys" issues Ken Brown
2017-11-30 12:53 ` Jon Turney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171128145605.12860-2-kbrown@cornell.edu \
--to=kbrown@cornell.edu \
--cc=cygwin-apps@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).