diff --git a/loadsave.c b/loadsave.c index 356399af..b475ca6f 100644 --- a/loadsave.c +++ b/loadsave.c @@ -510,15 +510,6 @@ void Get_full_filename(char * filename, byte is_colorix_format) // Gestion des lectures et écritures // ///////////////////////////////////////////////////////////////////////////// -void Read_one_byte(FILE * file, byte *b) -{ - // FIXME : Replace les appelants par Read_bytes(), et gérer les retours d'erreur. - if (!Read_byte(file, b)) - File_error=2; -} - -// -------------------------------------------------------------------------- - byte * Write_buffer; word Write_buffer_index; @@ -1185,7 +1176,11 @@ void Load_PKM(void) // Boucle de décompression: while ( (Compteur_de_pixels 127 alors il faut répéter 256-'temp_byte' fois la couleur de l'octet suivant // Si temp_byte <= 127 alors il faut afficher directement les 'temp_byte' octets suivants if (temp_byte>127) { - Read_one_byte(LBM_file, &color); + if(Read_byte(LBM_file, &color)!=1) + { + File_error=2; + break; + } b256=(short)(256-temp_byte); for (counter=0; counter<=b256; counter++) if (x_pos=line_size || Read_byte(LBM_file, &(LBM_buffer[x_pos++]))!=1) + File_error=2; } if (!File_error) Draw_ILBM_line(y_pos,real_line_size); @@ -1938,10 +1951,18 @@ void Load_LBM(void) { for (x_pos=0; ((x_pos127) { - Read_one_byte(LBM_file, &color); + if(Read_byte(LBM_file, &color)!=1) + { + File_error=2; + break; + } b256=256-temp_byte; for (counter=0; counter<=b256; counter++) Pixel_load_function(x_pos++,y_pos,color); @@ -1950,7 +1971,11 @@ void Load_LBM(void) for (counter=0; counter<=temp_byte; counter++) { byte byte_read=0; - Read_one_byte(LBM_file, &byte_read); + if(Read_byte(LBM_file, &byte_read)!=1) + { + File_error=2; + break; + } Pixel_load_function(x_pos++,y_pos,byte_read); } } @@ -2429,8 +2454,8 @@ void Load_BMP(void) y_pos=Main_image_height-1; /*Init_lecture();*/ - Read_one_byte(file, &a); - Read_one_byte(file, &b); + if(Read_byte(file, &a)!=1 || Read_byte(file, &b)!=1) + File_error=2; while (!File_error) { if (a) // Encoded mode @@ -2446,15 +2471,16 @@ void Load_BMP(void) case 1 : // End of bitmap break; case 2 : // Delta - Read_one_byte(file, &a); - Read_one_byte(file, &b); + if(Read_byte(file, &a)!=1 || Read_byte(file, &b)!=1) + File_error=2; x_pos+=a; y_pos-=b; break; default: // Nouvelle série while (b) { - Read_one_byte(file, &a); + if(Read_byte(file, &a)!=1) + File_error=2; //Read_one_byte(file, &c); Pixel_load_function(x_pos++,y_pos,a); //if (--c) @@ -2468,8 +2494,10 @@ void Load_BMP(void) } if (a==0 && b==1) break; - Read_one_byte(file, &a); - Read_one_byte(file, &b); + if(Read_byte(file, &a) !=1 || Read_byte(file, &b)!=1) + { + File_error=2; + } } /*Close_lecture();*/ break; @@ -2479,8 +2507,8 @@ void Load_BMP(void) y_pos=Main_image_height-1; /*Init_lecture();*/ - Read_one_byte(file, &a); - Read_one_byte(file, &b); + if(Read_byte(file, &a)!=1 || Read_byte(file, &b) != 1) + File_error =2; while ( (!File_error) && ((a)||(b!=1)) ) { if (a) // Encoded mode (A fois les 1/2 pixels de B) @@ -2502,8 +2530,8 @@ void Load_BMP(void) case 1 : // End of bitmap break; case 2 : // Delta - Read_one_byte(file, &a); - Read_one_byte(file, &b); + if(Read_byte(file, &a)!=1 || Read_byte(file, &b)!=1) + File_error=2; x_pos+=a; y_pos-=b; break; @@ -2512,7 +2540,7 @@ void Load_BMP(void) { if (index&1) { - Read_one_byte(file, &c); + if(Read_byte(file, &c)!=1) File_error=2; Pixel_load_function(x_pos,y_pos,c>>4); } else @@ -2523,11 +2551,10 @@ void Load_BMP(void) if ( ((b&3)==1) || ((b&3)==2) ) { byte dummy; - Read_one_byte(file, &dummy); + if(Read_byte(file, &dummy)!=1) File_error=2; } } - Read_one_byte(file, &a); - Read_one_byte(file, &b); + if(Read_byte(file, &a)!=1 || Read_byte(file, &b)!=1) File_error=2; } /*Close_lecture();*/ } @@ -2849,8 +2876,11 @@ void Test_GIF(void) // Si on a atteint la fin du bloc de Raster Data if (GIF_remainder_byte==0) // Lire l'octet nous donnant la taille du bloc de Raster Data suivant - Read_one_byte(GIF_file, &GIF_remainder_byte); - Read_one_byte(GIF_file,&GIF_last_byte); + if(Read_byte(GIF_file, &GIF_remainder_byte)!=1) + File_error=2; + + if(Read_byte(GIF_file,&GIF_last_byte)!=1) + File_error = 2; GIF_remainder_byte--; GIF_remainder_bits=8; } @@ -3842,13 +3872,13 @@ void Load_PCX(void) for (position=0; ((position> 4)); } else @@ -4308,7 +4338,7 @@ void Load_CEL(void) for (x_pos=0;((x_pos> 4)); } else @@ -4320,7 +4350,7 @@ void Load_CEL(void) for (x_pos=0;((x_pos