<?xml version="1.0" encoding="UTF-8"?>
	<rss version="2.0"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:wfw="http://wellformedweb.org/CommentAPI/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:atom="http://www.w3.org/2005/Atom"

			>

	<channel>
		<title>Cycling 74  &#187;  Topic: allocating new string (re: how to apply oo within max)</title>
		<atom:link href="http://cycling74.com/forums/topic/allocating-new-string-re-how-to-apply-oo-within-max/feed" rel="self" type="application/rss+xml" />
		<link>http://cycling74.com/forums/topic/allocating-new-string-re-how-to-apply-oo-within-max/feed</link>
		<description></description>
		<pubDate>Thu, 20 Jun 2013 00:42:35 +0000</pubDate>
		<generator>http://bbpress.org/?v=2.2.4</generator>
		<language></language>

		
														
					
				<item>
					<guid>http://cycling74.com/forums/topic/allocating-new-string-re-how-to-apply-oo-within-max/#post-32601</guid>
					<title><![CDATA[allocating new string (re: how to apply oo within max)]]></title>
					<link>http://cycling74.com/forums/topic/allocating-new-string-re-how-to-apply-oo-within-max/#post-32601</link>
					<pubDate>Sun, 24 Jun 2007 21:05:24 +0000</pubDate>
					<dc:creator>Mattijs</dc:creator>

					<description>
						<![CDATA[
						<p>Hi johnpitcairn,</p>
<p>Just a short question: in the other thread you advised me to allocate the correct amount of memory for a string copy like this:</p>
<p>str = malloc(strlen(path->s_name));<br />
if(str != NULL) strcpy(str, path->s_name);</p>
<p>&#8230;do stuff&#8230;</p>
<p>free(str);</p>
<p>instead of char str[1024];</p>
<p>When I use your method I get occasional crashes when reloading the abstraction (oo.call) that contains this external. When I switch back to the old method there are no more crashes. </p>
<p>I wonder, is there something obvious I am overlooking? Apart from adding one more char for &#8220;/0&#8243;? I suppose this would be better:</p>
<p>str = malloc(strlen(path->s_name) + 1);</p>
<p>Is that correct?</p>
<p>But I still get crashes.</p>
<p>Thanks,<br />
Mattijs</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/allocating-new-string-re-how-to-apply-oo-within-max/#post-107632</guid>
					<title><![CDATA[Re: allocating new string (re: how to apply oo within max)]]></title>
					<link>http://cycling74.com/forums/topic/allocating-new-string-re-how-to-apply-oo-within-max/#post-107632</link>
					<pubDate>Sun, 24 Jun 2007 21:09:40 +0000</pubDate>
					<dc:creator>Jeremy Bernstein</dc:creator>

					<description>
						<![CDATA[
						<p>str = malloc(strlen(path->s_name) + 1)</p>
<p>is correct and necessary!</p>
<p>But if you&#8217;re still getting crashes, then you&#8217;re looking at a  <br />
different problem. Are you sure that path is a valid t_symbol * (and  <br />
not NULL) when you call strlen and strcpy on it?</p>
<p>jb</p>
<p>Am 24.06.2007 um 23:05 schrieb Mattijs Kneppers:</p>
<p>><br />
> Hi johnpitcairn,<br />
><br />
> Just a short question: in the other thread you advised me to  <br />
> allocate the correct amount of memory for a string copy like this:<br />
><br />
> str = malloc(strlen(path->s_name));<br />
> if(str != NULL) strcpy(str, path->s_name);<br />
><br />
> &#8230;do stuff&#8230;<br />
><br />
> free(str);<br />
><br />
> instead of char str[1024];<br />
><br />
> When I use your method I get occasional crashes when reloading the  <br />
> abstraction (oo.call) that contains this external. When I switch  <br />
> back to the old method there are no more crashes.<br />
><br />
> I wonder, is there something obvious I am overlooking? Apart from  <br />
> adding one more char for &#8220;/0&#8243;? I suppose this would be better:<br />
><br />
> str = malloc(strlen(path->s_name) + 1);<br />
><br />
> Is that correct?<br />
><br />
> But I still get crashes.<br />
><br />
> Thanks,<br />
> Mattijs<br />
> &#8211;<br />
> SmadSteck &#8211; <a href="http://www.smadsteck.nl" rel="nofollow">http://www.smadsteck.nl</a><br />
> Hard- and software for interactive audiovisual sampling</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/allocating-new-string-re-how-to-apply-oo-within-max/#post-107633</guid>
					<title><![CDATA[Re: allocating new string (re: how to apply oo within max)]]></title>
					<link>http://cycling74.com/forums/topic/allocating-new-string-re-how-to-apply-oo-within-max/#post-107633</link>
					<pubDate>Sun, 24 Jun 2007 21:28:39 +0000</pubDate>
					<dc:creator>Mattijs</dc:creator>

					<description>
						<![CDATA[
						<p>Wow, that&#8217;s what I call a quick reply! Thanks for the confirmation of the + 1. </p>
<p>path comes all the way from a patcher argument. So it&#8217;s not a bad guess that it isn&#8217;t correctly initialized prior to this call. In fact the crashes also occur in what from the crash reports seems to be a GUI update (not intiated in my external) and I&#8217;d say patcher arguments are the only way to make that happen when I&#8217;m not programming a gui object.</p>
<p>It&#8217;s strange though that this only happens once in appr. 5 times I save the abstraction that contains the external, maybe something to do with an accidental collision with a screen refresh?</p>
<p>The method in which the strcpy is done is called as a result of a deferred loadbang. I think everything should be properly initialized by then, no?</p>
<p>Thanks,<br />
Mattijs</p>
<p>P.s. one other thing I think I should do is put the &#8220;do stuff&#8221; inside the if:</p>
<p>str = malloc(strlen(path->s_name) + 1);<br />
if(str != NULL) <br />
{<br />
strcpy(str, path->s_name);</p>
<p>&#8230;do stuff&#8230;</p>
<p>free(str);<br />
}</p>
<p>
I attached some crash reports.</p>
<p>
Quote: Jeremy Bernstein wrote on Sun, 24 June 2007 23:09<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
> str = malloc(strlen(path->s_name) + 1)<br />
> <br />
> is correct and necessary!<br />
> <br />
> But if you&#8217;re still getting crashes, then you&#8217;re looking at a  <br />
> different problem. Are you sure that path is a valid t_symbol * (and  <br />
> not NULL) when you call strlen and strcpy on it?<br />
> <br />
> jb<br />
> <br />
> Am 24.06.2007 um 23:05 schrieb Mattijs Kneppers:<br />
> <br />
> ><br />
> > Hi johnpitcairn,<br />
> ><br />
> > Just a short question: in the other thread you advised me to  <br />
> > allocate the correct amount of memory for a string copy like this:<br />
> ><br />
> > str = malloc(strlen(path->s_name));<br />
> > if(str != NULL) strcpy(str, path->s_name);<br />
> ><br />
> > &#8230;do stuff&#8230;<br />
> ><br />
> > free(str);<br />
> ><br />
> > instead of char str[1024];<br />
> ><br />
> > When I use your method I get occasional crashes when reloading the  <br />
> > abstraction (oo.call) that contains this external. When I switch  <br />
> > back to the old method there are no more crashes.<br />
> ><br />
> > I wonder, is there something obvious I am overlooking? Apart from  <br />
> > adding one more char for &#8220;/0&#8243;? I suppose this would be better:<br />
> ><br />
> > str = malloc(strlen(path->s_name) + 1);<br />
> ><br />
> > Is that correct?<br />
> ><br />
> > But I still get crashes.<br />
> ><br />
> > Thanks,<br />
> > Mattijs<br />
> > &#8211;<br />
> > SmadSteck &#8211; <a href="http://www.smadsteck.nl" rel="nofollow">http://www.smadsteck.nl</a><br />
> > Hard- and software for interactive audiovisual sampling<br />
> <br />
> <br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/allocating-new-string-re-how-to-apply-oo-within-max/#post-107634</guid>
					<title><![CDATA[Re: allocating new string (re: how to apply oo within max)]]></title>
					<link>http://cycling74.com/forums/topic/allocating-new-string-re-how-to-apply-oo-within-max/#post-107634</link>
					<pubDate>Sun, 24 Jun 2007 21:33:21 +0000</pubDate>
					<dc:creator>$adam</dc:creator>

					<description>
						<![CDATA[
						<p></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/allocating-new-string-re-how-to-apply-oo-within-max/#post-107635</guid>
					<title><![CDATA[Re: allocating new string (re: how to apply oo within max)]]></title>
					<link>http://cycling74.com/forums/topic/allocating-new-string-re-how-to-apply-oo-within-max/#post-107635</link>
					<pubDate>Sun, 24 Jun 2007 21:47:39 +0000</pubDate>
					<dc:creator>Mattijs</dc:creator>

					<description>
						<![CDATA[
						<p></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/allocating-new-string-re-how-to-apply-oo-within-max/#post-107636</guid>
					<title><![CDATA[Re: allocating new string (re: how to apply oo within max)]]></title>
					<link>http://cycling74.com/forums/topic/allocating-new-string-re-how-to-apply-oo-within-max/#post-107636</link>
					<pubDate>Mon, 25 Jun 2007 00:20:07 +0000</pubDate>
					<dc:creator>johnpitcairn</dc:creator>

					<description>
						<![CDATA[
						<p>Apologies to Mattijs for the wild goose chase, I forgot the essential +1 when I made that post&#8230;</p>
						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

