@@ -55,14 +55,13 @@ static int OpenRomDirFile(const struct ROMImgStat *ImageStat, const char *file,
5555{
5656 const struct RomDirEntry * RomDirEntry ;
5757 int result ;
58- unsigned int offset ;
5958
6059 memset (fd , 0 , sizeof (struct RomDirFileFd ));
6160
6261 RomDirEntry = ImageStat -> ROMFS_start ;
6362 result = ENOENT ;
6463 if (GetRomDirExtInfoOffset (ImageStat , fd ) == 0 ) {
65- offset = 0 ;
64+ unsigned int offset = 0 ;
6665 while (RomDirEntry -> name [0 ] != '\0' ) {
6766 if (strncmp (file , RomDirEntry -> name , sizeof (RomDirEntry -> name )) == 0 ) {
6867 fd -> FileOffset = offset ;
@@ -86,12 +85,11 @@ static int GetExtInfoStat(const struct ROMImgStat *ImageStat, struct RomDirFileF
8685{
8786 int result ;
8887 unsigned int offset , BytesToCopy ;
89- struct ExtInfoFieldEntry * ExtInfoEntry ;
9088
9189 result = ENOENT ;
9290 offset = 0 ;
9391 while (offset < fd -> ExtInfoEntrySize ) {
94- ExtInfoEntry = (struct ExtInfoFieldEntry * )((RMIMG_PTRCAST )ImageStat -> image + fd -> ExtInfoOffset );
92+ struct ExtInfoFieldEntry * ExtInfoEntry = (struct ExtInfoFieldEntry * )((RMIMG_PTRCAST )ImageStat -> image + fd -> ExtInfoOffset );
9593
9694 if (ExtInfoEntry -> type == EXTINFO_FIELD_TYPE_DATE || ExtInfoEntry -> type == EXTINFO_FIELD_TYPE_COMMENT ) {
9795 if (type == ExtInfoEntry -> type ) {
@@ -155,7 +153,7 @@ int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg)
155153
156154 ROMImg -> date = GetSystemDate ();
157155#if defined(_WIN32 ) || defined(WIN32 )
158- int x = GetUsername (UserName , sizeof (UserName ));
156+ GetUsername (UserName , sizeof (UserName ));
159157#else
160158 UserName = getenv ("USER" );
161159#endif
@@ -187,12 +185,10 @@ int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg)
187185
188186int WriteROMImg (const char * file , const ROMIMG * ROMImg )
189187{
190- int result , FileAlignMargin ;
191- FILE * OutputFile ;
188+ int result ;
192189 unsigned char * extinfo ;
193190 struct RomDirEntry ROMDIR_romdir , EXTINFO_romdir , NULL_romdir ;
194191 unsigned int i , TotalExtInfoSize , ExtInfoOffset , CommentLengthRounded ;
195- struct ExtInfoFieldEntry * ExtInfoEntry ;
196192
197193 result = 0 ;
198194 ExtInfoOffset = 0 ;
@@ -201,7 +197,7 @@ int WriteROMImg(const char *file, const ROMIMG *ROMImg)
201197 for (i = 0 , TotalExtInfoSize = 0 ; i < ROMImg -> NumFiles ; i ++ ) {
202198 TotalExtInfoSize += ROMImg -> files [i ].RomDir .ExtInfoEntrySize ;
203199 if (ROMImg -> files [i ].RomDir .ExtInfoEntrySize % 4 != 0 ) {
204- WARNING ("ASSERT ROMImg->files[%d ].RomDir.ExtInfoEntrySize%%4==0\n" , i );
200+ WARNING ("ASSERT ROMImg->files[%u ].RomDir.ExtInfoEntrySize%%4==0\n" , i );
205201 abort ();
206202 }
207203 }
@@ -219,7 +215,7 @@ int WriteROMImg(const char *file, const ROMIMG *ROMImg)
219215 strcpy (ROMDIR_romdir .name , "ROMDIR" );
220216 ROMDIR_romdir .size = (ROMImg -> NumFiles + 3 ) * sizeof (struct RomDirEntry ); // Number of files (Including RESET) + one ROMDIR and one EXTINFO entries... and one NULL entry.
221217 ROMDIR_romdir .ExtInfoEntrySize = sizeof (struct ExtInfoFieldEntry ) + CommentLengthRounded ;
222- ExtInfoEntry = (struct ExtInfoFieldEntry * )(extinfo + ExtInfoOffset );
218+ struct ExtInfoFieldEntry * ExtInfoEntry = (struct ExtInfoFieldEntry * )(extinfo + ExtInfoOffset );
223219 ExtInfoEntry -> value = 0 ;
224220 ExtInfoEntry -> ExtLength = CommentLengthRounded ;
225221 ExtInfoEntry -> type = EXTINFO_FIELD_TYPE_COMMENT ;
@@ -232,14 +228,16 @@ int WriteROMImg(const char *file, const ROMIMG *ROMImg)
232228
233229 for (i = 1 ; i < ROMImg -> NumFiles ; i ++ ) {
234230 if (ExtInfoOffset % 4 != 0 ) {
235- printf ("ASSERT: ExtInfoOffset[%d ]%%4==0: %d \n" , i , ExtInfoOffset );
231+ WARNING ("ASSERT: ExtInfoOffset[%u ]%%4==0: %u \n" , i , ExtInfoOffset );
236232 abort ();
237233 }
238234 memcpy (& extinfo [ExtInfoOffset ], ROMImg -> files [i ].ExtInfoData , ROMImg -> files [i ].RomDir .ExtInfoEntrySize );
239235 ExtInfoOffset += ROMImg -> files [i ].RomDir .ExtInfoEntrySize ;
240236 }
241237
238+ FILE * OutputFile ;
242239 if ((OutputFile = fopen (file , "wb" )) != NULL ) {
240+ int FileAlignMargin ;
243241 // Write the content of RESET (The bootstrap program, if it exists).
244242 fwrite (ROMImg -> files [0 ].FileData , 1 , ROMImg -> files [0 ].RomDir .size , OutputFile ); // It will be aligned to 16 byte units in size.
245243
@@ -279,8 +277,7 @@ int LoadROMImg(ROMIMG *ROMImg, const char *path)
279277{
280278 FILE * InputFile ;
281279 int result ;
282- unsigned int i , offset , ExtInfoOffset , DataStartOffset , ScanLimit , CommentLength ;
283- struct RomDirEntry * RomDir ;
280+ unsigned int ExtInfoOffset , DataStartOffset , ScanLimit , CommentLength ;
284281 struct RomDirFileFd RomDirFileFd ;
285282 struct ROMImgStat ImageStat ;
286283 struct FileEntry * file ;
@@ -297,6 +294,7 @@ int LoadROMImg(ROMIMG *ROMImg, const char *path)
297294 DataStartOffset = 0 ;
298295
299296 // Scan for the start of the image, which is after the end of the bootstrap program. All regular IOPRP images don't have one (The image begins immediately at the start of the file).
297+ unsigned int i ;
300298 for (i = 0 , result = - EIO , ScanLimit = 0x40000 < ImageStat .size ? 0x40000 : ImageStat .size ; i < ScanLimit ; i ++ ) {
301299
302300 if (((const char * )ImageStat .image )[i ] == 'R' &&
@@ -336,8 +334,8 @@ int LoadROMImg(ROMIMG *ROMImg, const char *path)
336334 ROMImg -> comment = NULL ;
337335 GetExtInfoStat (& ImageStat , & RomDirFileFd , EXTINFO_FIELD_TYPE_COMMENT , & ROMImg -> comment , 0 );
338336
339- RomDir = (struct RomDirEntry * )ImageStat .ROMFS_start ;
340- offset = 0 ;
337+ struct RomDirEntry * RomDir = (struct RomDirEntry * )ImageStat .ROMFS_start ;
338+ unsigned int offset = 0 ;
341339 ExtInfoOffset = 0 ;
342340 GetRomDirExtInfoOffset (& ImageStat , & RomDirFileFd );
343341 while (RomDir -> name [0 ] != '\0' ) {
@@ -363,19 +361,19 @@ int LoadROMImg(ROMIMG *ROMImg, const char *path)
363361 result = EINVAL ;
364362 }
365363 } else {
366- DPRINTF ("failed to read %d bytes\n" , ImageStat .size );
364+ ERROR ("failed to read %u bytes\n" , ImageStat .size );
367365 result = EIO ;
368366 }
369367
370368 free (ImageStat .image );
371369 } else {
372- ERROR ("failed to malloc %d bytes\n" , ImageStat .size );
370+ ERROR ("failed to malloc %u bytes\n" , ImageStat .size );
373371 result = ENOMEM ;
374372 }
375373
376374 fclose (InputFile );
377375 } else {
378- DPRINTF ("cant open '%s'\n" , path );
376+ ERROR ("cant open '%s'\n" , path );
379377 result = ENOENT ;
380378 }
381379
@@ -385,12 +383,12 @@ int LoadROMImg(ROMIMG *ROMImg, const char *path)
385383void UnloadROMImg (ROMIMG * ROMImg )
386384{
387385 DPRINTF ("start...\n" );
388- unsigned int i ;
389386
390387 if (ROMImg -> comment != NULL ) {
391388 free (ROMImg -> comment );
392389 }
393390 if (ROMImg -> files != NULL ) {
391+ unsigned int i ;
394392 for (i = 0 ; i < ROMImg -> NumFiles ; i ++ ) {
395393 if (ROMImg -> files [i ].ExtInfoData != NULL )
396394 free (ROMImg -> files [i ].ExtInfoData );
@@ -458,16 +456,16 @@ static int AddExtInfoStat(struct FileEntry *file, unsigned char type, void *data
458456int AddFile (ROMIMG * ROMImg , const char * path )
459457{
460458 FILE * InputFile ;
461- int result , size ;
459+ int result ;
462460 unsigned int FileDateStamp ;
463461 unsigned short FileVersion ;
464- char ModuleDescription [32 ];
465- struct FileEntry * file ;
466462 if ((InputFile = fopen (path , "rb" )) != NULL ) {
463+ int size ;
467464 fseek (InputFile , 0 , SEEK_END );
468465 size = ftell (InputFile );
469466 rewind (InputFile );
470467
468+ struct FileEntry * file ;
471469 // Files cannot exist more than once in an image. The RESET entry is special here because all images will have a RESET entry, but it might be empty (If it has no content, allow the user to add in content).
472470 if (strcmp (path , "RESET" )) {
473471 if (!IsFileExists (ROMImg , path )) {
@@ -484,6 +482,7 @@ int AddFile(ROMIMG *ROMImg, const char *path)
484482 AddExtInfoStat (& ROMImg -> files [ROMImg -> NumFiles - 1 ], EXTINFO_FIELD_TYPE_DATE , & FileDateStamp , 4 );
485483
486484 if (IsSonyRXModule (path )) {
485+ char ModuleDescription [32 ];
487486 if ((result = GetSonyRXModInfo (path , ModuleDescription , sizeof (ModuleDescription ), & FileVersion )) == 0 ) {
488487 AddExtInfoStat (& ROMImg -> files [ROMImg -> NumFiles - 1 ], EXTINFO_FIELD_TYPE_VERSION , & FileVersion , 2 );
489488 AddExtInfoStat (& ROMImg -> files [ROMImg -> NumFiles - 1 ], EXTINFO_FIELD_TYPE_COMMENT , ModuleDescription , strlen (ModuleDescription ) + 1 );
@@ -521,11 +520,11 @@ int AddFile(ROMIMG *ROMImg, const char *path)
521520int DeleteFile (ROMIMG * ROMImg , const char * filename )
522521{
523522 int result ;
524- unsigned int i ;
525523 struct FileEntry * file ;
526524
527- // The RESET entry cannot be detected , but its content will be.
525+ // The RESET entry cannot be deleted , but its content will be.
528526 if (strcmp ("RESET" , filename )) {
527+ unsigned int i ;
529528 for (result = ENOENT , i = 0 , file = ROMImg -> files ; i < ROMImg -> NumFiles ; i ++ , file ++ ) {
530529 if (strncmp (file -> RomDir .name , filename , sizeof (file -> RomDir .name )) == 0 ) {
531530 if (file -> FileData != NULL )
0 commit comments