@@ -805,11 +805,10 @@ int main( int argc, char **argv ) {
805
805
exiso_log ( "%s is already optimized, skipping...\n" , argv [ i ] );
806
806
continue ;
807
807
}
808
-
809
- if ( ! err && ( buf = (char * ) malloc ( strlen ( argv [ i ] ) + 5 ) ) == nil ) mem_err (); // + 5 magic number is for ".old\0"
808
+
810
809
if ( ! err ) {
811
- sprintf ( buf , "%s.old" , argv [ i ] );
812
- if ( stat ( buf , & sb ) != -1 ) misc_err ( "%s already exists, cannot rewrite %s\n" , buf , argv [ i ], 0 );
810
+ if ( asprintf ( & buf , "%s.old" , argv [i ]) == -1 ) mem_err ( );
811
+ if ( ! err && stat ( buf , & sb ) != -1 ) misc_err ( "%s already exists, cannot rewrite %s\n" , buf , argv [ i ], 0 );
813
812
if ( ! err && rename ( argv [ i ], buf ) == -1 ) misc_err ( "cannot rename %s to %s\n" , argv [ i ], buf , 0 );
814
813
815
814
if ( err ) { err = 0 ; free ( buf ); continue ; }
@@ -1151,10 +1150,8 @@ int decode_xiso( char *in_xiso, char *in_path, modes in_mode, char **out_iso_pat
1151
1150
if ( in_path [ path_len - 1 ] != PATH_CHAR ) ++ add_slash ;
1152
1151
}
1153
1152
1154
- if ( ( buf = (char * ) malloc ( path_len + add_slash + strlen ( iso_name ) + 2 ) ) == nil ) mem_err ();
1155
-
1156
- if ( ! err ) {
1157
- sprintf ( buf , "%s%s%s%c" , in_path ? in_path : "" , add_slash && ( ! in_path ) ? PATH_CHAR_STR : "" , in_mode != k_list && ( ! in_path ) ? iso_name : "" , PATH_CHAR );
1153
+ if (!err ) {
1154
+ if (asprintf (& buf , "%s%s%s%c" , in_path ? in_path : "" , add_slash && (!in_path ) ? PATH_CHAR_STR : "" , in_mode != k_list && (!in_path ) ? iso_name : "" , PATH_CHAR ) == -1 ) mem_err ()
1158
1155
1159
1156
if (!err && lseek (xiso , (xoff_t )root_dir_sect * XISO_SECTOR_SIZE + s_xbox_disc_lseek , SEEK_SET ) == -1 ) seek_err ();
1160
1157
@@ -1166,7 +1163,7 @@ int decode_xiso( char *in_xiso, char *in_path, modes in_mode, char **out_iso_pat
1166
1163
if (!err ) err = traverse_xiso (xiso , (xoff_t )root_dir_sect * XISO_SECTOR_SIZE + s_xbox_disc_lseek , 0 , buf , in_mode , nil );
1167
1164
}
1168
1165
1169
- free ( buf );
1166
+ if ( buf ) free ( buf );
1170
1167
}
1171
1168
}
1172
1169
0 commit comments