Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 672416DE17D7 for ; Sat, 29 Aug 2015 07:56:47 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: -0.322 X-Spam-Level: X-Spam-Status: No, score=-0.322 tagged_above=-999 required=5 tests=[AWL=0.398, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RnYGQTNEmNdK for ; Sat, 29 Aug 2015 07:56:45 -0700 (PDT) Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com [209.85.212.176]) by arlo.cworth.org (Postfix) with ESMTPS id 6B6036DE1552 for ; Sat, 29 Aug 2015 07:56:45 -0700 (PDT) Received: by wicne3 with SMTP id ne3so9345296wic.0 for ; Sat, 29 Aug 2015 07:56:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=7x21swL2LRVephKeotLrwmieDqRaO00TDhQTFy28Q6k=; b=PvDF5BMMZrU5mAQhKHsgspX1B+SuJfZXxrWhtW6Oj6g/XIeqXXR9yMdrv1jAc3ViIb 046GjHgi9UNjlLm7APVdEPUZ+/OhjuD/n/Y9w/Nhp6ROQcR/SRsp7r8vQQckRKA3lLx7 w0s0WhKovzQgzZqthme1RtM1bvgy196eJX46JSyOd0Vz+3v+hPAMci6rlMv2GUPwXD6M JnEGxM5bgH6bxzghuG5p2K4Yy9V2vzZeWAQHtwFTU0qe6pWYbBC4pfbwiW4P1fRdEmap e0Vchanefc/abwuPlrv0lQyi/n/G2lGekXodBdJxrLL+p9A5x7uNMJ/5NuyPvDg35185 AuVw== X-Gm-Message-State: ALoCoQnO80z6rnwuLyBdWVJ8N5ln9pCDPk7vcQJ+VIjCHO0Ke/+nEsiKvVgTQnTe1KqtJKWMjetn X-Received: by 10.180.89.99 with SMTP id bn3mr9762037wib.61.1440860203417; Sat, 29 Aug 2015 07:56:43 -0700 (PDT) Received: from localhost (mobile-access-bcee4f-131.dhcp.inet.fi. [188.238.79.131]) by smtp.gmail.com with ESMTPSA id yu4sm13137828wjc.43.2015.08.29.07.56.42 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 29 Aug 2015 07:56:42 -0700 (PDT) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [RFC PATCH 2/5] cli: abstract new mailbox creation Date: Sat, 29 Aug 2015 17:56:33 +0300 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.18 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: Sat, 29 Aug 2015 14:56:47 -0000 We'll be needing more mailbox creation soon, so abstract it away. While at it, check for allocation failures. No other functional changes. --- notmuch-search.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/notmuch-search.c b/notmuch-search.c index 7fdc6acaa2fe..36f58eb8d54c 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -243,6 +243,21 @@ do_search_threads (search_context_t *ctx) return 0; } +static mailbox_t *new_mailbox (void *ctx, const char *name, const char *addr) +{ + mailbox_t *mailbox; + + mailbox = talloc (ctx, mailbox_t); + if (! mailbox) + return NULL; + + mailbox->name = talloc_strdup (mailbox, name); + mailbox->addr = talloc_strdup (mailbox, addr); + mailbox->count = 1; + + return mailbox; +} + /* Returns TRUE iff name and addr is duplicate. If not, stores the * name/addr pair in order to detect subsequent duplicates. */ static notmuch_bool_t @@ -262,10 +277,10 @@ is_duplicate (const search_context_t *ctx, const char *name, const char *addr) return TRUE; } - mailbox = talloc (ctx->format, mailbox_t); - mailbox->name = talloc_strdup (mailbox, name); - mailbox->addr = talloc_strdup (mailbox, addr); - mailbox->count = 1; + mailbox = new_mailbox (ctx->format, name, addr); + if (! mailbox) + return FALSE; + g_hash_table_insert (ctx->addresses, key, mailbox); return FALSE; -- 2.1.4