<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Bug: dat utility/grabber crashes</title>
		<link>http://www.allegro.cc/forums/view/558565</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 22 Jan 2006 23:06:08 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello folks!<br />I have the following problem:<br />Whenever I try to save a datafile using the dat utility or the grabber, it crashes.</p><p>Also the grabber doesn&#39;t shut down properly whenever I run it: I just start it, select &quot;File-&gt;Quit&quot; and there comes a Windows-message about the program not exiting properly... <br />I have compiled the debug-version of Allegro now, using that the grabber program produces no error at shut-down.<br />But still, when I try to save a datafile, I get an error message:
</p><pre>
&gt;dat -a -t bmp -bpp 16 elevator.dat *.bmp
elevator.dat not found: creating new datafile
Inserting d:\prog\shdw\objs\ELEVATOR\FLY_0001.bmp -&gt; FLY_0001_BMP
Inserting d:\prog\shdw\objs\ELEVATOR\PROP.bmp -&gt; PROP_BMP
Inserting d:\prog\shdw\objs\ELEVATOR\STILL.bmp -&gt; STILL_BMP
Writing elevator.dat
Assert failed at line 2300 of src/file.c
</pre><p>

This is about line 2300 of src/file.c:</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="c">/* pack_mputw:</span></td></tr><tr><td class="number">2</td><td><span class="c"> *  Writes a 16 bit int to a file, using motorola byte-ordering.</span></td></tr><tr><td class="number">3</td><td><span class="c"> */</span></td></tr><tr><td class="number">4</td><td><span class="k1">int</span> <a href="http://www.allegro.cc/manual/pack_mputw" target="_blank"><span class="a">pack_mputw</span></a><span class="k2">(</span><span class="k1">int</span> w, <a href="http://www.allegro.cc/manual/PACKFILE" target="_blank"><span class="a">PACKFILE</span></a> <span class="k3">*</span>f<span class="k2">)</span></td></tr><tr><td class="number">5</td><td><span class="k2">{</span></td></tr><tr><td class="number">6</td><td>   <span class="k1">int</span> b1, b2<span class="k2">;</span></td></tr><tr><td class="number">7</td><td>   <a href="http://www.allegro.cc/manual/ASSERT" target="_blank"><span class="a">ASSERT</span></a><span class="k2">(</span>f<span class="k2">)</span><span class="k2">;</span>  <span class="c">/* &lt;---- 2300 is here */</span></td></tr><tr><td class="number">8</td><td>&#160;</td></tr><tr><td class="number">9</td><td>   b1 <span class="k3">=</span> <span class="k2">(</span>w <span class="k3">&amp;</span> <span class="n">0xFF00</span><span class="k2">)</span> <span class="k3">&gt;</span><span class="k3">&gt;</span> <span class="n">8</span><span class="k2">;</span></td></tr><tr><td class="number">10</td><td>   b2 <span class="k3">=</span> w <span class="k3">&amp;</span> <span class="n">0x00FF</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>&#160;</td></tr><tr><td class="number">12</td><td>   <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/pack_putc" target="_blank"><span class="a">pack_putc</span></a><span class="k2">(</span>b1,f<span class="k2">)</span><span class="k3">=</span><span class="k3">=</span>b1<span class="k2">)</span></td></tr><tr><td class="number">13</td><td>      <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/pack_putc" target="_blank"><span class="a">pack_putc</span></a><span class="k2">(</span>b2,f<span class="k2">)</span><span class="k3">=</span><span class="k3">=</span>b2<span class="k2">)</span></td></tr><tr><td class="number">14</td><td>   <span class="k1">return</span> w<span class="k2">;</span></td></tr><tr><td class="number">15</td><td>&#160;</td></tr><tr><td class="number">16</td><td>   <span class="k1">return</span> EOF<span class="k2">;</span></td></tr><tr><td class="number">17</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>


I&#39;m running Allegro 4.2 on Windows XP.</p><p>edit: Forgot to say, there is no file saved, which is my real problem <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>Does anyone have any clue?<br />Thanks!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BigBertus)</author>
		<pubDate>Mon, 09 Jan 2006 23:05:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Do you have write permission in the target directory? What happens if you run as root (or whatever the Windows equivalent is called)?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Mon, 09 Jan 2006 23:14:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Aaaah! With administrator-privileges, it does write the datafile, thanks!</p><p>But I certainly do have permission to create/write files in the target directory.<br />I forgot to mention, when I don&#39;t log on as administrator, there is a file created that has 0 bytes. So when there is a file created, why do I need administrator-privileges to write into it?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BigBertus)</author>
		<pubDate>Mon, 09 Jan 2006 23:40:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t know, but I&#39;ve seen this same issue come up before. I don&#39;t remember what causes it, but maybe a forum search will help you.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Tue, 10 Jan 2006 00:11:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, yes.<br />I found this thread:<br /><a href="http://www.allegro.cc/forums/thread/454214">http://www.allegro.cc/forums/thread/454214</a><br />However the actual cause of the problem is not got rid of by using that fix- I am on an NTFS drive, of course, so it&#39;s the same problem...<br />It&#39;s strange, everything but just the grabber and dat-utility works on NTFS?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BigBertus)</author>
		<pubDate>Tue, 10 Jan 2006 01:24:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can you run dat through a debugger?  If you see why the assertion is being triggered that would possibly lead you to the source of the problem.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Tue, 10 Jan 2006 04:52:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I tried to do that, but my debugger keeps crashing. I&#39;m using Insight, which is more or less a graphical frontend for gdb, I think. Does anyone know another working debugger for MinGW? (except for gdb, but if there is none, I could also try that)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BigBertus)</author>
		<pubDate>Wed, 11 Jan 2006 02:09:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I found the bug, but I don&#39;t have time to fix it. If someone could fix it, that would be great.  Here is the problem: there is a call to pack_fopen_chunk() in datedit.c that fails.  Due to some sloppy coding, this was not checked.  pack_fopen_chunk() is implemented by opening a temporary file so even if you have write access to the target directory it could fail if you don&#39;t have write access to the directory for the temporary file (I think it is the current directory).  Someone needs to fix pack_fopen_chunk().</p><p>In the meantime, I will apply a patch so at least dat and grabber will return a failure code rather than aborting.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Sat, 21 Jan 2006 07:01:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Patch for pack_fopen_chunk() attached. Someone please test it in Windows, since I forgot to do this. It works fine now in Linux, but the code used in Windows is slightly different.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Sun, 22 Jan 2006 21:54:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;d check it, but I&#39;ve never had problems with grabber under WinXP (and I use NTFS).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Sun, 22 Jan 2006 22:52:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have a problem with the following part:</p><div class="source-code snippet"><div class="inner"><pre>         <span class="k1">do</span> <span class="k2">{</span>
            size <span class="k3">=</span> new_size<span class="k2">;</span>
            tmp_dir <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_648.html" target="_blank">realloc</a><span class="k2">(</span>tmp_dir, size<span class="k2">)</span><span class="k2">;</span>
            new_size <span class="k3">=</span> GetTempPath<span class="k2">(</span>size, tmp_dir<span class="k2">)</span><span class="k2">;</span>
         <span class="k2">}</span> <span class="k1">while</span> <span class="k2">(</span> <span class="k2">(</span>size <span class="k3">&gt;</span> new_size<span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> <span class="k2">(</span>new_size <span class="k3">&gt;</span> <span class="n">0</span><span class="k2">)</span> <span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/gettemppath.asp">GetTempPath</a> returns 0 on error. If that piece of code is trying to increase the buffer size to try again, it is not doing so. However, even if it does, it is possible that the temporary directory could not be retrieved, thus creating an infinite loop draining all memory. I would remove the while cycle; after the loop it is checked if it could not be extracted.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Sun, 22 Jan 2006 22:55:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I&#39;d check it, but I&#39;ve never had problems with grabber under WinXP (and I use NTFS).
</p></div></div><p>
It has nothing to do with WinXP - it has to do with trying to create a file in a directory where you do not have write permission (so I was also able to reproduce it in Linux as well).<br />Go to a directory where you don&#39;t have write permission, start the grabber from there and safe a datafile in a directory where you do have write permission. The grabber will then try to create a temporary file in the active directory, where you don&#39;t have write permission, and crash.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
GetTempPath [msdn.microsoft.com] returns 0 on error. If that piece of code is trying to increase the buffer size to try again, it is not doing so. However, even if it does, it is possible that the temporary directory could not be retrieved, thus creating an infinite loop draining all memory.
</p></div></div><p>
That&#39;s why there&#39;s a <i>&amp;&amp; (new_size &gt; 0)</i> in there.<br />The code should run until it either fails or retrieves the directory after a couple of iterations.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Sun, 22 Jan 2006 23:01:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh, didn&#39;t read the second part, the one saying it would return only the size <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" /></p><p>Since it returns the size in TCHAR, it may have problems with unicode (can Allegro be compiled in a Unicode project in MSVC?). Maybe it would be safer to multiply sizes with <i>sizeof(TCHAR)</i>? If not, dismiss that <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Sun, 22 Jan 2006 23:06:08 +0000</pubDate>
	</item>
</rss>
