Skip to content

Commit 481a9b0

Browse files
committed
Replace all malloc+sprintf with asprintf
1 parent 0ec1d41 commit 481a9b0

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

extract-xiso.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -805,11 +805,10 @@ int main( int argc, char **argv ) {
805805
exiso_log( "%s is already optimized, skipping...\n", argv[ i ] );
806806
continue;
807807
}
808-
809-
if ( ! err && ( buf = (char *) malloc( strlen( argv[ i ] ) + 5 ) ) == nil ) mem_err(); // + 5 magic number is for ".old\0"
808+
810809
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 );
813812
if ( ! err && rename( argv[ i ], buf ) == -1 ) misc_err( "cannot rename %s to %s\n", argv[ i ], buf, 0 );
814813

815814
if ( err ) { err = 0; free( buf ); continue; }
@@ -1154,10 +1153,8 @@ int decode_xiso( char *in_xiso, char *in_path, modes in_mode, char **out_iso_pat
11541153
if ( in_path[ path_len - 1 ] != PATH_CHAR ) ++add_slash;
11551154
}
11561155

1157-
if ( ( buf = (char *) malloc( path_len + add_slash + strlen( iso_name ) + 2 ) ) == nil ) mem_err();
1158-
1159-
if ( ! err ) {
1160-
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 );
1156+
if (!err) {
1157+
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()
11611158

11621159
if (!err && lseek(xiso, (xoff_t)root_dir_sect * XISO_SECTOR_SIZE + s_xbox_disc_lseek, SEEK_SET) == -1) seek_err();
11631160

@@ -1169,7 +1166,7 @@ int decode_xiso( char *in_xiso, char *in_path, modes in_mode, char **out_iso_pat
11691166
if (!err) err = traverse_xiso(xiso, (xoff_t)root_dir_sect * XISO_SECTOR_SIZE + s_xbox_disc_lseek, 0, buf, in_mode, nil);
11701167
}
11711168

1172-
free( buf );
1169+
if(buf) free(buf);
11731170
}
11741171
}
11751172

0 commit comments

Comments
 (0)