Bug in allegro filestytem? I think that reads are drifting!
nshade

I think I have a test case here. When reading in data from a file, allegro is randomly pushing the read index ahead one.

Here is the output from reading a zip file with no compression.

Quote:

Got Header
Read in 4 bytes After header, now at 4
Skipped ahead 18 bytes , now at 22
Read in 4 bytes for filesize - now at 26
Filesize=79152
Read in two bytes namesize - now at 28
Namesize=9
Still at 28 skipping 2 bytes
skpped 2 bytes Now at filename 30
filename read in 9 bytes , Now at 39
adjusted filename should still be at 39
Filename=alert.ogg
skipping ahead 79152 bytes
Skiped File! Now at 79191
Got Header
Read in 4 bytes After header, now at 79195
Skipped ahead 18 bytes , now at 79213
Read in 4 bytes for filesize - now at 79217
Filesize=275
Read in two bytes namesize - now at 79219
Namesize=9
Still at 79219 skipping 2 bytes
skpped 2 bytes Now at filename 79221
filename read in 9 bytes , Now at 79230
adjusted filename should still be at 79230
Filename=arrow.png
skipping ahead 275 bytes
Skiped File! Now at 79505
Got Header
Read in 4 bytes After header, now at 79509
Skipped ahead 18 bytes , now at 79527
Read in 4 bytes for filesize - now at 79531
Filesize=12662
Read in two bytes namesize - now at 79533
Namesize=8
Still at 79533 skipping 2 bytes
skpped 2 bytes Now at filename 79535
filename read in 8 bytes , Now at 79543
adjusted filename should still be at 79543
Filename=beam.ogg
skipping ahead 12662 bytes
Skiped File! Now at 92205
Got Header
Read in 4 bytes After header, now at 92209
Skipped ahead 18 bytes , now at 92227
Read in 4 bytes for filesize - now at 92232
Filesize=707366
Read in two bytes namesize - now at 92234
Namesize=15
Still at 92234 skipping 2 bytes
skpped 2 bytes Now at filename 92236
filename read in 15 bytes , Now at 92251
adjusted filename should still be at 92251
Filename=border_back.png
skipping ahead 707366 bytes
Skiped File! Now at 799617
NO HEADER!

Pay close attention to the first and last reads..

Quote:

------
First read
------
Got Header
Read in 4 bytes After header, now at 4 (+4)
Skipped ahead 18 bytes , now at 22 (+18)
Read in 4 bytes for filesize - now at 26 (+4)
Filesize=79152
Read in two bytes namesize - now at 28 (+4)
Namesize=9
Still at 28 skipping 2 bytes
skpped 2 bytes Now at filename 30 (+2)
filename read in 9 bytes , Now at 39 (+9)
adjusted filename should still be at 39
Filename=alert.ogg
skipping ahead 79152 bytes
Skiped File! Now at 79191 (+79152)

------
Last read before failure:
------
Skiped File! Now at 92205
Got Header
Read in 4 bytes After header, now at 92209 (+4)
Skipped ahead 18 bytes , now at 92227 (+18)
Read in 4 bytes for filesize - now at 92232 (+5!!!! <------- IT IS NOW REPORTING +1 AHEAD OF THE SEEK POINTER!)
Filesize=707366 (This is correct!?)
Read in two bytes namesize - now at 92234 (wrong location!)
Namesize=15 (Still read in correct data, al_ftell(); is reporting +1 of where the seek pointer actually is)
Still at 92234 skipping 2 bytes
skpped 2 bytes Now at filename 92236
filename read in 15 bytes , Now at 92251
adjusted filename should still be at 92251
Filename=border_back.png (all of these are being read in properly even though al_ftell(); is still +1 bytes ahead of the actual seek pointer.
skipping ahead 707366 bytes
Skiped File! Now at 799617 (seek pointer and al_ftell() pointer now match, but now is off by +1 byte and is unable to read the header)
NO HEADER!

It seems to be screwing up doing a read after an al_fseek()

Here is my example code. To test yourself, use a zip file named default.zip with a few uncompressed files inside.

==EDIT==
I Attached an example zip file. This one is even more wacky because if you al_fseek() after the header read it reports that it's -29 bytes into the file

Windows 10 x64 BTW

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_primitives.h> 4#include <allegro5/allegro_image.h> 5#include <allegro5/allegro_video.h> 6#include <allegro5/allegro_font.h> 7#include <allegro5/allegro_ttf.h> 8 9ALLEGRO_DISPLAY *d; 10ALLEGRO_FILE *zip; 11ALLEGRO_FILE *target; 12 13 14void startup() 15{ 16 if (!al_init()) { 17 fprintf(stderr, "failed to initialize allegro!\n"); 18 exit(1); 19 } 20 if (!al_install_keyboard()) { 21 fprintf(stderr, "Error installing keyboard.\n"); 22 exit(1); 23 } 24 25 if (!al_init_primitives_addon()) { 26 fprintf(stderr, "Error installing prims.\n"); 27 exit(1); 28 } 29 30 if (!al_init_image_addon()) { 31 fprintf(stderr, "Error installing image addon.\n"); 32 exit(1); 33 } 34 35 36 if (!al_init_font_addon()) { 37 fprintf(stderr, "Error installing font addon.\n"); 38 exit(1); 39 } 40 41 if (!al_init_ttf_addon()) { 42 fprintf(stderr, "Error installing TTF addon.\n"); 43 exit(1); 44 } 45 46 47 d = al_create_display(1024, 768); 48 al_clear_to_color(al_map_rgb(0, 0, 0)); 49 50 51} 52 53 54int main(int argc, char **argv) 55{ 56 int header; 57 int filesize; 58 int namesize; 59 char filename[255]; 60 61 62 startup(); 63 zip=al_fopen("default.zip", "r"); 64 while (!al_feof(zip)) { 65 66 67 header = al_fread32le(zip); 68 if (header == 0x04034b50) { printf("Got Header\n"); } 69 else { printf("NO HEADER!\n"); exit(1); } 70 printf("Read in 4 bytes After header, now at %d\n", al_ftell(zip)); 71 al_fseek(zip, 18, ALLEGRO_SEEK_CUR); 72 printf("Skipped ahead 18 bytes , now at %d\n", al_ftell(zip)); 73 filesize = al_fread32le(zip); 74 printf("Read in 4 bytes for filesize - now at %d\n", al_ftell(zip)); 75 printf("Filesize=%d\n", filesize); 76 namesize = al_fread16le(zip); 77 printf("Read in two bytes namesize - now at %d\n", al_ftell(zip)); 78 printf("Namesize=%d\n", namesize); 79 printf("Still at %d skipping 2 bytes\n", al_ftell(zip)); 80 al_fread16le(zip); //skip 2 81 printf("skpped 2 bytes Now at filename %d\n", al_ftell(zip)); 82 al_fread(zip, filename, namesize); 83 printf("filename read in %d bytes , Now at %d\n",namesize, al_ftell(zip)); 84 filename[namesize] = '\0'; 85 printf("adjusted filename should still be at %d\n", al_ftell(zip)); 86 printf("Filename=%s\n", filename); 87 printf("skipping ahead %d bytes\n", filesize); 88 al_fseek(zip, filesize, ALLEGRO_SEEK_CUR); 89 printf("Skipped File! Now at %d\n", al_ftell(zip)); 90 } 91 92 93 while (1);

Edgar Reynaldo
nshade

HEADDESK

Man, Windows! Why do you make me want to hurt you?

Audric

Actually it's libc's choice that unless you open files with "b" flag, the mode is "text" (And MS-DOS choice of line ending)

Edgar Reynaldo

That's pretty much the first thing you learn when doing io. Binary or text mode.

Thread #617628. Printed from Allegro.cc