[vhd] improve handing of user selected filename on save to VHD/FFU

* Use of '*.*' as pattern in file save dialog could lead to assert and crash, so
  we now try to derive the type of image to be saved from the file extension. We
  also did not properly handle user cancellation in the file save dialog.
* Also update iso9660/iso9660_fs.c to latest proposal of El Torito image handling.
* Also add a couple asserts in the hash table functions so that, if these ever get
  triggered we will pick them from Windows Store reports, and clean up code.
This commit is contained in:
Pete Batard 2024-02-03 18:38:17 +00:00
parent 018ed3414b
commit c2b2624b62
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
4 changed files with 61 additions and 26 deletions

View file

@ -80,8 +80,9 @@ BOOL htab_create(uint32_t nel, htab_table* htab)
if (htab == NULL) {
return FALSE;
}
assert(htab->table == NULL);
if (htab->table != NULL) {
uprintf("warning: htab_create() was called with a non empty table");
uprintf("Warning: htab_create() was called with a non empty table");
return FALSE;
}
@ -96,7 +97,7 @@ BOOL htab_create(uint32_t nel, htab_table* htab)
// allocate memory and zero out.
htab->table = (htab_entry*)calloc(htab->size + 1, sizeof(htab_entry));
if (htab->table == NULL) {
uprintf("could not allocate space for hash table\n");
uprintf("Could not allocate space for hash table");
return FALSE;
}
@ -166,7 +167,7 @@ uint32_t htab_hash(char* str, htab_table* htab)
// existing hash
return idx;
}
// uprintf("hash collision ('%s' vs '%s')\n", str, htab->table[idx].str);
// uprintf("Hash collision ('%s' vs '%s')", str, htab->table[idx].str);
// Second hash function, as suggested in [Knuth]
hval2 = 1 + hval % (htab->size - 2);
@ -196,19 +197,20 @@ uint32_t htab_hash(char* str, htab_table* htab)
// Not found => New entry
// If the table is full return an error
assert(htab->filled < htab->size);
if (htab->filled >= htab->size) {
uprintf("hash table is full (%d entries)", htab->size);
uprintf("Hash table is full (%d entries)", htab->size);
return 0;
}
safe_free(htab->table[idx].str);
htab->table[idx].used = hval;
htab->table[idx].str = (char*) malloc(safe_strlen(str)+1);
htab->table[idx].str = (char*) malloc(safe_strlen(str) + 1);
if (htab->table[idx].str == NULL) {
uprintf("could not duplicate string for hash table\n");
uprintf("Could not duplicate string for hash table");
return 0;
}
memcpy(htab->table[idx].str, str, safe_strlen(str)+1);
memcpy(htab->table[idx].str, str, safe_strlen(str) + 1);
++htab->filled;
return idx;