mirror of
https://gitlab.com/80486DX2-66/gists
synced 2024-11-08 18:02:23 +05:30
reverse-ramdisk.c: fix segmentation fault, remove index check
This commit is contained in:
parent
be048aa266
commit
03f7a5460a
@ -93,11 +93,6 @@ int tf_alloc(size_t n, size_t type_size) {
|
||||
temp_file->file_path = strdup(file_path);
|
||||
temp_file->file = file;
|
||||
|
||||
// Add the temp file to the array
|
||||
temp_files[num_temp_files] = *temp_file;
|
||||
|
||||
num_temp_files++;
|
||||
|
||||
// Allocate/reallocate memory for the temp_files structure
|
||||
if (temp_files == NULL)
|
||||
temp_files = malloc(sizeof(TempFile));
|
||||
@ -109,15 +104,15 @@ int tf_alloc(size_t n, size_t type_size) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Add the temp file to the array
|
||||
temp_files[num_temp_files++] = *temp_file;
|
||||
|
||||
return temp_file->ID;
|
||||
}
|
||||
|
||||
int tf_free(int ID) {
|
||||
size_t index = (size_t) ID;
|
||||
|
||||
if (index == -1)
|
||||
return -1;
|
||||
|
||||
fclose(temp_files[index].file);
|
||||
|
||||
// Delete the file
|
||||
@ -148,9 +143,6 @@ int tf_free(int ID) {
|
||||
int tf_write(int ID, size_t offset, void* data, size_t data_size) {
|
||||
size_t index = (size_t) ID;
|
||||
|
||||
if (index == -1)
|
||||
return -1;
|
||||
|
||||
// Check file handler for NULL
|
||||
FILE* file = temp_files[index].file;
|
||||
if (file == NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user