[AD] [ alleg-Bugs-1911984 ] pack_fwrite stop working after saving more than 10.000 elems

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Bugs item #1911984, was opened at 2008-03-11 15:59
Message generated for change (Settings changed) made by elias
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105665&aid=1911984&group_id=5665

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core Library
Group: None
>Status: Closed
Resolution: Invalid
Priority: 5
Private: No
Submitted By: L_Dev (l_devil)
Assigned to: Nobody/Anonymous (nobody)
Summary: pack_fwrite stop working after saving more than 10.000 elems

Initial Comment:
DESCRIPTION:

Allegro version 4.2.2.0 precompiled for MSVC 2005 grabbed from allegro.cc gave unexpected behavior during save of vast amount of small portion of data by "pack_write".

HOW TO REPRODUCE:

Following code reproduces the error. It was tested on x86 machine with Windows XP SP2. It was compiled on free Microsoft Visual C++ Express 2005

############################ - CODE BEGINS HERE

#define _CRT_SECURE_NO_WARNINGS // for MSVC 2005 and newer

#include <allegro.h>
#if defined WIN32 || defined _WINDOWS
#include <winalleg.h>
#endif
#include <cstdlib>

#if defined WIN32 || defined _WINDOWS
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, char * Cmd, int nShow)
#else
int main(int argc, char ** argv)
#endif
{
	if(allegro_init()!=0)
		return 1;

	packfile_password(NULL);
	PACKFILE * pack = pack_fopen("./test.txt", F_WRITE);
	for(int i=0; i<5000; i++)
	{
		char temp[25];
		_itoa(i, temp, 10);
		if(pack_fwrite(temp, strlen(temp), pack)!=strlen(temp))
		{
			allegro_message(allegro_error);
			return 1;
		}
		strcpy(temp, ".) ");
		if(pack_fwrite(temp, strlen(temp), pack)!=strlen(temp))
		{
			allegro_message(allegro_error);
			return 1;
		}
		if(pack_fwrite(&i, sizeof(i), pack)!=sizeof(i))
		{
			allegro_message(allegro_error);
			return 1;
		}
		if(pack_fwrite("\r\n", strlen("\r\n"), pack)!=strlen("\r\n"))
		{
			allegro_message(allegro_error);
			return 1;
		}
	}
	allegro_message("Operation Successful");
	allegro_exit();
	return 0;
}

############################ - CODE ENDS HERE.

Result? Allegro gave "Operation Successful" message, but file "./test.txt" ends on 4810 entry (and that entry is incomplete) and is missing next 190 entries!
To notice: all functions reports nothing off the ordinary, Allegro says that everything goes correctly.

----------------------------------------------------------------------

>Comment By: Elias Pschernig (elias)
Date: 2008-10-06 19:31

Message:
I agree, seems it was a matter of a forgotten pack_fclose after all.
Closing it.

----------------------------------------------------------------------

Comment By: Peter Hull (peterhull90)
Date: 2008-10-06 19:10

Message:
I think this is now closed. Anyone else have an opinion?

----------------------------------------------------------------------

Comment By: L_Dev (l_devil)
Date: 2008-03-12 20:25

Message:
Logged In: YES 
user_id=1362424
Originator: YES

Nevermind, I wrote

if(!pack_fclose(pack))
   return false;

and I should

if(pack_fclose(pack)!=0)
   return false;

----------------------------------------------------------------------

Comment By: L_Dev (l_devil)
Date: 2008-03-12 12:04

Message:
Logged In: YES 
user_id=1362424
Originator: YES

Oh, that's strange. In my app (10.000 lines of code) there is
pack_fclose(pack); and yet still doesn't save everything...

Oh, I got it. I didn't realized that pack_fclose may fail. Now I test it
and it fails, but errno is equal to 0. Any ideas?

----------------------------------------------------------------------

Comment By: Milan Mimica (mmimica)
Date: 2008-03-11 18:38

Message:
Logged In: YES 
user_id=1171214
Originator: NO

Calling pack_fclose(pack); at the end seems to fix the problem.

----------------------------------------------------------------------

Comment By: L_Dev (l_devil)
Date: 2008-03-11 16:10

Message:
Logged In: YES 
user_id=1362424
Originator: YES

Sorry, it seems that Sourceforge.net ate tabs. I hope this will be no
problem :-)

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105665&aid=1911984&group_id=5665




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/