[PATCH 2/4] emacs: Fix exception when fetching empty or unconfigured settings
authorAustin Clements <amdragon@MIT.EDU>
Thu, 20 Feb 2014 19:16:35 +0000 (14:16 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:00:06 +0000 (10:00 -0800)
5e/561f9fe9ec7549e7ba776a860ff2a329c49be8 [new file with mode: 0644]

diff --git a/5e/561f9fe9ec7549e7ba776a860ff2a329c49be8 b/5e/561f9fe9ec7549e7ba776a860ff2a329c49be8
new file mode 100644 (file)
index 0000000..bbd2f31
--- /dev/null
@@ -0,0 +1,113 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 1FF9B431FC7\r
+       for <notmuch@notmuchmail.org>; Thu, 20 Feb 2014 11:16:50 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id K2q9j2y5TfW6 for <notmuch@notmuchmail.org>;\r
+       Thu, 20 Feb 2014 11:16:46 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu\r
+       [18.9.25.14])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id C2CC3431FBF\r
+       for <notmuch@notmuchmail.org>; Thu, 20 Feb 2014 11:16:46 -0800 (PST)\r
+X-AuditID: 1209190e-f79ee6d000000c40-0b-5306549e3659\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       (using TLS with cipher AES256-SHA (256/256 bits))\r
+       (Client did not present a certificate)\r
+       by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 6F.61.03136.E9456035; Thu, 20 Feb 2014 14:16:46 -0500 (EST)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s1KJGhK2005934; \r
+       Thu, 20 Feb 2014 14:16:43 -0500\r
+Received: from drake.dyndns.org (26-4-182.dynamic.csail.mit.edu [18.26.4.182])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s1KJGf42012829\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Thu, 20 Feb 2014 14:16:42 -0500\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1WGZ6v-0004Z8-1q; Thu, 20 Feb 2014 14:16:41 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/4] emacs: Fix exception when fetching empty or unconfigured\r
+       settings\r
+Date: Thu, 20 Feb 2014 14:16:35 -0500\r
+Message-Id: <1392923797-17045-3-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.8.4.rc3\r
+In-Reply-To: <1392923797-17045-1-git-send-email-amdragon@mit.edu>\r
+References: <1392923797-17045-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixG6nrjsvhC3YoOGNosXrBZPYLK7fnMns\r
+       wOSxem0ni8ezVbeYA5iiuGxSUnMyy1KL9O0SuDLOnZ7NWLCYu2LLluVsDYydnF2MnBwSAiYS\r
+       G3+8Y4ewxSQu3FvP1sXIxSEkMJtJYt7up1DORkaJRf1LWSCcI0wS93+3QGXmMkrsXfcIrJ9N\r
+       QENi2/7ljCC2iIC0xM67s1lBbGYBG4nNHx+DxYUFwiROX5rDAmKzCKhKbPx9hgnE5hVwkFi5\r
+       cyYLxB1KEgtPbQPr5RRwlFja/wHI5gBa5iDRuVVnAiP/AkaGVYyyKblVurmJmTnFqcm6xcmJ\r
+       eXmpRbrGermZJXqpKaWbGEGhxCnJt4Px60GlQ4wCHIxKPLwnpdiChVgTy4orcw8xSnIwKYny\r
+       rggACvEl5adUZiQWZ8QXleakFh9ilOBgVhLhbbIByvGmJFZWpRblw6SkOViUxHlrLX4FCQmk\r
+       J5akZqemFqQWwWRlODiUJHjnBQM1ChalpqdWpGXmlCCkmTg4QYbzAA2PDAIZXlyQmFucmQ6R\r
+       P8WoKCXO+xQkIQCSyCjNg+uFxforRnGgV4R5E0FW8ADTBFz3K6DBTECDSzayggwuSURISTUw\r
+       ztuzYYZRa3/J2izO29tCZZ67ivN5K5yaeZgvzPRW3UKP7CXnDZ7r7922Nor53MOsjmtKMkvV\r
+       NFnC8wWX6bxelGS0RfCe8pYv17x0Dq6wO67evN5CR4/LLoul95GwgVlffO31XsvNUlM/ab7c\r
+       uUidp+7tbW+95N7vuu/3LZXPfLT52o8zv9bOU2Ipzkg01GIuKk4EAMGYhbfQAgAA\r
+Cc: bjonnh-nm@bjonnh.net\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 20 Feb 2014 19:16:50 -0000\r
+\r
+When "notmuch config" is called with the name of an empty or\r
+unconfigured setting, it prints nothing (not even a new line).\r
+Previously, `notmuch-config-get' assumed it would always print a\r
+newline.  As a result, when `notmuch-config-get' was called with the\r
+name of an empty of unconfigured setting, it would attempt to\r
+(substring "" 0 -1) to strip the newline, which would fail with a\r
+(args-out-of-range "" 0 -1) exception.\r
+\r
+Fix this by only stripping the newline if there actually is one.\r
+---\r
+ emacs/notmuch-lib.el | 9 +++++++--\r
+ 1 file changed, 7 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index fa35fa9..09110b5 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -198,8 +198,13 @@ on the command line, and then retry your notmuch command")))\r
\r
+ (defun notmuch-config-get (item)\r
+   "Return a value from the notmuch configuration."\r
+-  ;; Trim off the trailing newline\r
+-  (substring (notmuch-command-to-string "config" "get" item) 0 -1))\r
++  (let* ((val (notmuch-command-to-string "config" "get" item))\r
++       (len (length val)))\r
++    ;; Trim off the trailing newline (if the value is empty or not\r
++    ;; configured, there will be no newline)\r
++    (if (and (> len 0) (= (aref val (- len 1)) ?\n))\r
++      (substring val 0 -1)\r
++      val)))\r
\r
+ (defun notmuch-database-path ()\r
+   "Return the database.path value from the notmuch configuration."\r
+-- \r
+1.8.4.rc3\r
+\r