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 93E9F431FBF for ; Sat, 27 Apr 2013 09:05:49 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.299 X-Spam-Level: X-Spam-Status: No, score=-2.299 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_MED=-2.3, UNPARSEABLE_RELAY=0.001] 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 rsB0oxVyYv-d for ; Sat, 27 Apr 2013 09:05:49 -0700 (PDT) Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 449FB431FAE for ; Sat, 27 Apr 2013 09:05:49 -0700 (PDT) Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r3RG5j9S028392 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 27 Apr 2013 16:05:46 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r3RG5iAd008228 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Sat, 27 Apr 2013 16:05:45 GMT Received: from ubhmt108.oracle.com (ubhmt108.oracle.com [156.151.24.13]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r3RG5iRx010412; Sat, 27 Apr 2013 16:05:44 GMT Received: from vi64-x3-2e-prg06.cz.oracle.com (/10.163.102.127) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Apr 2013 09:05:43 -0700 Date: Sat, 27 Apr 2013 18:05:40 +0200 From: Vladimir Marek To: Jani Nikula Subject: Re: [PATCH] don't store temporary value returned from c_str() Message-ID: <20130427160540.GB17459@vi64-x3-2e-prg06.cz.oracle.com> References: <1366405933-17223-1-git-send-email-Vladimir.Marek@oracle.com> <878v44qhop.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <878v44qhop.fsf@nikula.org> User-Agent: Mutt/ (2012-12-30) X-Source-IP: acsinet22.oracle.com [141.146.126.238] Cc: notmuch@notmuchmail.org, Vladimir Marek 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: Sat, 27 Apr 2013 16:05:49 -0000 > It's okay to use the result of .c_str() as long as the string object > stays in scope, and none of the non-const member functions are > called. Here, I think the problem is that TermIterator's overloaded > operator*() returns a string object within the if block's scope, and it > goes immediately out of scope. You could check this by adding Right, I overlooked that TermIterator creates temporary string (if I understand you correctly). > > string s = *i; > > in function scope, and replacing (*i) with s in the if block. This might > also be more obvious than the presented patch, but I think the patch is > fine too. I would prefer my change as it avoids creating another std::string. At least I think. Thank you -- Vlad