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