1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-12-24 22:59:49 +05:30

reverse-ramdisk.c: fix segmentation fault, remove index check

This commit is contained in:
Intel A80486DX2-66 2023-12-28 00:07:29 +03:00
parent be048aa266
commit 03f7a5460a
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -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)