unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Vladimir Marek <Vladimir.Marek@Oracle.COM>
To: Tomi Ollila <tomi.ollila@iki.fi>
Cc: notmuch@notmuchmail.org, Vladimir Marek <vlmarek@volny.cz>
Subject: Re: [PATCH] don't store temporary value returned from c_str()
Date: Sat, 27 Apr 2013 12:11:35 +0200	[thread overview]
Message-ID: <20130427101134.GI10394@pub.cz.oracle.com> (raw)
In-Reply-To: <m2sj2cjp2b.fsf@guru.guru-group.fi>

> > From: Vladimir Marek <vlmarek@volny.cz>
> >
> > This is causing problems when compiled by Oracle Studio. Memory pointed
> > by (const char*)term was already changed once talloc_strdup was called.
> 
> If that changes, I'd like to understand why (and stated in the commit
> message). If that is clear to everyone else I will withdraw the question --
> I am not too familiar with these iterators magic... :D

Well, a) standards says that

A temporary bound to a reference parameter in a function call (5.2.2)
persists until the completion of the full expression containing the call

(you can find the message all over the net, but I can't find actual link
to the standard :-/)


b) Imagine the function c_str() looks like that:

const char*
string::c_str(void) {
	char buf[100];

	strcpy (buf, this->internal_representation);
	return buf;
}

you can't do:
char *my_tmp = string.c_str();
printf(my_tmp);

you can do:
printf(string.c_str());

Hopefully I made the example right ...

Cheers
-- 
	Vlad

  reply	other threads:[~2013-04-27 10:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-19 21:12 [PATCH] don't store temporary value returned from c_str() Vladimir.Marek
2013-04-27  9:33 ` Tomi Ollila
2013-04-27 10:11   ` Vladimir Marek [this message]
2013-04-27 11:53     ` David Bremner
2013-04-27 15:59       ` Vladimir Marek
2013-04-30  6:12     ` Kim Minh Kaplan
2013-04-30  8:48       ` Vladimir Marek
2013-04-30  9:44         ` Kim Minh Kaplan
2013-05-01 11:28           ` Vladimir Marek
2013-04-27 12:30 ` Jani Nikula
2013-04-27 13:22   ` Tomi Ollila
2013-04-27 16:05   ` Vladimir Marek
2013-04-29 21:23     ` David Bremner
2013-05-01 21:33       ` Vladimir Marek

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

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130427101134.GI10394@pub.cz.oracle.com \
    --to=vladimir.marek@oracle.com \
    --cc=notmuch@notmuchmail.org \
    --cc=tomi.ollila@iki.fi \
    --cc=vlmarek@volny.cz \
    /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.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

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).