<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Aufruf einer Funktion führt zu Speicherzugriffsfehler]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich hab ein Problem bei dem Aufruf einer Funktion und weiß echt nicht mehr weiter. Bin der Meinung schon echt alles ausprobiert zu haben.</p>
<p>Das ganze Programm ist sehr umfangreich und deshalb hier ein Auschnitt:<br />
Aufruf der Funktion:</p>
<pre><code class="language-cpp">cout &lt;&lt; &quot;\n before UltraLocalProjection3D \n&quot;  &lt;&lt; endl;
      if(TDatabase::ParamDB-&gt;LP_FULL_GRADIENT)
        UltraLocalProjection3D(MatricesA[k], FALSE, BilinearCoeffs);
      cout &lt;&lt; &quot;\n after UltraLocalProjection3D \n&quot;  &lt;&lt; endl;
</code></pre>
<p>Ausschnitt aus der Funktion UltraLocalProjection3D:</p>
<pre><code class="language-cpp">void UltraLocalProjection3D(void* A, boolean ForPressure, CoeffFct3D *Coeff)
      {	  
	      cerr &lt;&lt; &quot;\n start of UltraLocalProjection3D \n&quot;  &lt;&lt; endl;
		  int i,j,k,l,m,n;
</code></pre>
<p>Als Ausgabe bekomme ich immer:</p>
<pre><code>before UltraLocalProjection3D

 Segmentation fault
</code></pre>
<p>MatricesA[k] sollte eigentlich ein Feld von Zeigern sein. Aber egal ob ich statt MatricesA[k] etwas anderes wie NULL, 0, ein Array von irgendeinem Datentyp einsetzte, es kommt immer wieder der gleich Fehler.</p>
<p>Ich habe gdb und valgrind drüber laufen lassen:</p>
<p>valgrind:</p>
<pre><code>before UltraLocalProjection3D

==4708== Warning: client switching stacks?  SP change: 0x7FEFFF0E0 --&gt; 0x7F87AA520
==4708==          to suppress, use: --max-stackframe=109398976 or greater
==4708==
==4708== Invalid write of size 8
==4708==    at 0x522DC8: UltraLocalProjection3D(void*, boolean, void (*)(int, double*, double*, double*, double**, double**)) (LocalProjection3D.C:283)
==4708==  Address 0x7F87AA598 is on thread 1's stack
==4708==
==4708== Process terminating with default action of signal 11 (SIGSEGV)
==4708==  Access not within mapped region at address 0x7F87AA598
==4708==    at 0x522DC8: UltraLocalProjection3D(void*, boolean, void (*)(int, double*, double*, double*, double**, double**)) (LocalProjection3D.C:283)
==4708==
==4708== Invalid write of size 8
==4708==    at 0x6A5B348: _vgnU_freeres (in /usr/lib64/valgrind/amd64-linux/vgpreload_core.so)
==4708==  Address 0x7F87AA518 is on thread 1's stack
==4708==
==4708== Process terminating with default action of signal 11 (SIGSEGV)
==4708==  Access not within mapped region at address 0x7F87AA518
==4708==    at 0x6A5B348: _vgnU_freeres (in /usr/lib64/valgrind/amd64-linux/vgpreload_core.so)
</code></pre>
<p>gdb</p>
<pre><code>before UltraLocalProjection3D

Program received signal SIGSEGV, Segmentation fault.
0x0000000000522df0 in UltraLocalProjection3D (A=Cannot access memory at address 0x7fff4440b1d8
) at ../LocalProjection3D.C:283
283     void UltraLocalProjection3D(void* A, boolean ForPressure, CoeffFct3D *Coeff)
(gdb) info stack
#0  0x0000000000522df0 in UltraLocalProjection3D (A=Cannot access memory at address 0x7fff4440b1d8
) at ../LocalProjection3D.C:283
#1  0x0000000000404eb4 in main (argc=2, argv=0x7fff4ac60978) at Tutorial/CD_3D_LPS.C:615
(gdb)
</code></pre>
<p>Warum hat er mit dem Aufruf der Funktion UltraLocalProjection3D solche Probleme? Wie kann es dazu kommen das er beim Aufruf der Funktion ein Speicherzugriffsfehler erzeugt?</p>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/272410/aufruf-einer-funktion-führt-zu-speicherzugriffsfehler</link><generator>RSS for Node</generator><lastBuildDate>Fri, 28 Aug 2026 22:18:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/272410.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 17 Aug 2010 11:02:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Aufruf einer Funktion führt zu Speicherzugriffsfehler on Tue, 17 Aug 2010 11:02:59 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich hab ein Problem bei dem Aufruf einer Funktion und weiß echt nicht mehr weiter. Bin der Meinung schon echt alles ausprobiert zu haben.</p>
<p>Das ganze Programm ist sehr umfangreich und deshalb hier ein Auschnitt:<br />
Aufruf der Funktion:</p>
<pre><code class="language-cpp">cout &lt;&lt; &quot;\n before UltraLocalProjection3D \n&quot;  &lt;&lt; endl;
      if(TDatabase::ParamDB-&gt;LP_FULL_GRADIENT)
        UltraLocalProjection3D(MatricesA[k], FALSE, BilinearCoeffs);
      cout &lt;&lt; &quot;\n after UltraLocalProjection3D \n&quot;  &lt;&lt; endl;
</code></pre>
<p>Ausschnitt aus der Funktion UltraLocalProjection3D:</p>
<pre><code class="language-cpp">void UltraLocalProjection3D(void* A, boolean ForPressure, CoeffFct3D *Coeff)
      {	  
	      cerr &lt;&lt; &quot;\n start of UltraLocalProjection3D \n&quot;  &lt;&lt; endl;
		  int i,j,k,l,m,n;
</code></pre>
<p>Als Ausgabe bekomme ich immer:</p>
<pre><code>before UltraLocalProjection3D

 Segmentation fault
</code></pre>
<p>MatricesA[k] sollte eigentlich ein Feld von Zeigern sein. Aber egal ob ich statt MatricesA[k] etwas anderes wie NULL, 0, ein Array von irgendeinem Datentyp einsetzte, es kommt immer wieder der gleich Fehler.</p>
<p>Ich habe gdb und valgrind drüber laufen lassen:</p>
<p>valgrind:</p>
<pre><code>before UltraLocalProjection3D

==4708== Warning: client switching stacks?  SP change: 0x7FEFFF0E0 --&gt; 0x7F87AA520
==4708==          to suppress, use: --max-stackframe=109398976 or greater
==4708==
==4708== Invalid write of size 8
==4708==    at 0x522DC8: UltraLocalProjection3D(void*, boolean, void (*)(int, double*, double*, double*, double**, double**)) (LocalProjection3D.C:283)
==4708==  Address 0x7F87AA598 is on thread 1's stack
==4708==
==4708== Process terminating with default action of signal 11 (SIGSEGV)
==4708==  Access not within mapped region at address 0x7F87AA598
==4708==    at 0x522DC8: UltraLocalProjection3D(void*, boolean, void (*)(int, double*, double*, double*, double**, double**)) (LocalProjection3D.C:283)
==4708==
==4708== Invalid write of size 8
==4708==    at 0x6A5B348: _vgnU_freeres (in /usr/lib64/valgrind/amd64-linux/vgpreload_core.so)
==4708==  Address 0x7F87AA518 is on thread 1's stack
==4708==
==4708== Process terminating with default action of signal 11 (SIGSEGV)
==4708==  Access not within mapped region at address 0x7F87AA518
==4708==    at 0x6A5B348: _vgnU_freeres (in /usr/lib64/valgrind/amd64-linux/vgpreload_core.so)
</code></pre>
<p>gdb</p>
<pre><code>before UltraLocalProjection3D

Program received signal SIGSEGV, Segmentation fault.
0x0000000000522df0 in UltraLocalProjection3D (A=Cannot access memory at address 0x7fff4440b1d8
) at ../LocalProjection3D.C:283
283     void UltraLocalProjection3D(void* A, boolean ForPressure, CoeffFct3D *Coeff)
(gdb) info stack
#0  0x0000000000522df0 in UltraLocalProjection3D (A=Cannot access memory at address 0x7fff4440b1d8
) at ../LocalProjection3D.C:283
#1  0x0000000000404eb4 in main (argc=2, argv=0x7fff4ac60978) at Tutorial/CD_3D_LPS.C:615
(gdb)
</code></pre>
<p>Warum hat er mit dem Aufruf der Funktion UltraLocalProjection3D solche Probleme? Wie kann es dazu kommen das er beim Aufruf der Funktion ein Speicherzugriffsfehler erzeugt?</p>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940924</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940924</guid><dc:creator><![CDATA[poohbaer]]></dc:creator><pubDate>Tue, 17 Aug 2010 11:02:59 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf einer Funktion führt zu Speicherzugriffsfehler on Tue, 17 Aug 2010 11:31:00 GMT]]></title><description><![CDATA[<p>Wenn Du das ganze Feld der Funktion übergibst, dann geschieht das über den Stack. Ist das Feld zu groß, so kommt es zum Stacküberlauf.</p>
<p>Kann es sein, das Du nicht &quot;void *A&quot; sondern evtl. void **A wolltest? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Gruß<br />
Trooper</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940941</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940941</guid><dc:creator><![CDATA[trooper]]></dc:creator><pubDate>Tue, 17 Aug 2010 11:31:00 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf einer Funktion führt zu Speicherzugriffsfehler on Tue, 17 Aug 2010 11:49:53 GMT]]></title><description><![CDATA[<p>Nein, das ist schon ok so. Hab mich wohl falsch ausgedrückt.</p>
<p>Aber die Zuweisung geschieht ungefähr folgender maßen:<br />
TSquareMatrix3D *sqmatrixA;<br />
[...]<br />
MatricesA[k] = sqmatrixA;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940952</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940952</guid><dc:creator><![CDATA[poohbaer]]></dc:creator><pubDate>Tue, 17 Aug 2010 11:49:53 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf einer Funktion führt zu Speicherzugriffsfehler on Tue, 17 Aug 2010 15:24:47 GMT]]></title><description><![CDATA[<p>poohbaer schrieb:</p>
<blockquote>
<p>Nein, das ist schon ok so. Hab mich wohl falsch ausgedrückt.</p>
<p>Aber die Zuweisung geschieht ungefähr folgender maßen:<br />
TSquareMatrix3D *sqmatrixA;<br />
[...]<br />
MatricesA[k] = sqmatrixA;</p>
</blockquote>
<p>das [...] ist wichtig ... falls da nicht noch irgendwo <code>sqmatrixA = new irgendwas[];</code> oder <code>sqmatrixA = &amp;neInitialisierteTSuareMatrix3D</code> (oder so ähnlich) kommt, hast du einen Zeiger der irgendwo hin zeigt und nicht dahin wo du schreiben darfst ...</p>
<p>mach mal <code>TSquareMatrix3D *sqmatrixA = 0;</code> und dann in der Zeile bevors kracht <code>if (! sqmatrixA) std::cout &lt;&lt; &quot;sqmatrixA zeigt sonst wo hin&quot; &lt;&lt; std::endl;</code></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1941090</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1941090</guid><dc:creator><![CDATA[padreigh]]></dc:creator><pubDate>Tue, 17 Aug 2010 15:24:47 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf einer Funktion führt zu Speicherzugriffsfehler on Tue, 17 Aug 2010 18:08:40 GMT]]></title><description><![CDATA[<p>padreigh schrieb:</p>
<blockquote>
<p>mach mal <code>TSquareMatrix3D *sqmatrixA = 0;</code> und dann in der Zeile bevors kracht <code>if (! sqmatrixA) std::cout &lt;&lt; &quot;sqmatrixA zeigt sonst wo hin&quot; &lt;&lt; std::endl;</code></p>
</blockquote>
<p>Das &quot;funktioniert&quot;. Aber sqmatrixA zeigt nur sonst wo hin wenn ich es vorher wie beschrieben 0 setze. Sonst scheint alles in Ordnung zu sein.</p>
<p>Hier mal im Wesentlichen die Zuweisung der von MatricesA[k]:</p>
<pre><code class="language-cpp">[...]
  TSquareStructure3D *sqstructureA;
  TSquareMatrix3D *sqmatrixA;
  TSquareMatrix3D **MatricesA;
  TFESpace3D *velocity_space;
  MatricesA = new TSquareMatrix3D*[LEVELS+1];
[...]
for(i=0;i&lt;LEVELS;i++)
{ 
  mg_level++;
  [...]  
  for(k=k0;k&lt;=mg_level;k++)
  {
	[...]
    if ((mg_type==1)&amp;&amp;(k&lt;mg_level))
      velocity_space =  new TFESpace3D(coll, Name, UString, BoundCondition, -1);
    else
      velocity_space =  new TFESpace3D(coll, Name, Description, BoundCondition, ORDER);
    // build matrices 
    sqstructureA = new TSquareStructure3D(velocity_space);
    sqstructureA-&gt;Sort();
    // allocate matrices
    sqmatrixA = new TSquareMatrix3D(sqstructureA);
    MatricesA[k] = sqmatrixA;
    [...]
  }
  [...]
}
[...]
</code></pre>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1941171</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1941171</guid><dc:creator><![CDATA[poohbaer]]></dc:creator><pubDate>Tue, 17 Aug 2010 18:08:40 GMT</pubDate></item><item><title><![CDATA[Reply to Aufruf einer Funktion führt zu Speicherzugriffsfehler on Tue, 17 Aug 2010 20:16:24 GMT]]></title><description><![CDATA[<p>Hmmm, ich habe jetzt noch mal etwas getestet und bin nun ganz verwirrt. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Ich habe die Funktion UltraLocalProjection3D so bearbeitet, dass sie unabhängig ist. Also nur noch</p>
<pre><code>UltraLocalProjection3D();
</code></pre>
<p>aufgerufen wird. Trotzdem wird mir ein Speicherzugriffsfehler ausgegeben.</p>
<p>Es ist doch richtig das er mit Hilfe von cerr eine Text-Ausgabe ungepuffert ausgibt,oder?</p>
<p>EDIT: Vielen Dank für die Ideen und Ansätze. Hab das Problem gelöst. In der Funktion UltraLocalProjection3D habe ich ein Array initialisiert, was anscheinend nicht zulässig war. Ich lebte in den Irrglauben das cerr mir eine Textausgabe ungepuffert ausgibt bevor er irgendwelche Variablen initielisiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1941205</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1941205</guid><dc:creator><![CDATA[poohbaer]]></dc:creator><pubDate>Tue, 17 Aug 2010 20:16:24 GMT</pubDate></item></channel></rss>