Fix bug in IsoFileSrc implementation, related to a wrogn usage of tsearch.
It happens that tsearch seems to not return a pointer to the inserted element, but a pointer to a pointer to the inserted element (that makes sense, as we are inserted pointers...). This bug, thus, was related to a wrong understanding of the tsearch API!
This commit is contained in:
parent
7b241176fb
commit
aa312cf7d7
@ -10,6 +10,7 @@
|
||||
#define LIBISO_ECMA119_H_
|
||||
|
||||
typedef struct ecma119_image Ecma119Image;
|
||||
typedef struct Iso_File_Src IsoFileSrc;
|
||||
|
||||
struct ecma119_image {
|
||||
|
||||
|
@ -32,7 +32,8 @@ int comp_iso_file_src(const void *n1, const void *n2)
|
||||
return 1;
|
||||
} else {
|
||||
/* files belong to same device in same fs */
|
||||
return f1->ino_id - f2->ino_id;
|
||||
return (f1->ino_id < f2->ino_id) ? -1 :
|
||||
(f1->ino_id > f2->ino_id) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -60,7 +61,7 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src)
|
||||
// Not implemented for now
|
||||
return ISO_ERROR;
|
||||
} else {
|
||||
IsoFileSrc *inserted;
|
||||
IsoFileSrc **inserted;
|
||||
|
||||
size = stream->get_size(stream);
|
||||
if (size == (off_t)-1) {
|
||||
@ -83,18 +84,18 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src)
|
||||
fsrc->stream = file->stream;
|
||||
|
||||
/* insert the filesrc in the tree */
|
||||
inserted = tsearch(fsrc, img->file_srcs, comp_iso_file_src);
|
||||
inserted = tsearch(fsrc, &(img->file_srcs), comp_iso_file_src);
|
||||
if (inserted == NULL) {
|
||||
free(fsrc);
|
||||
return ISO_MEM_ERROR;
|
||||
} else if (inserted == fsrc) {
|
||||
} else if (*inserted == fsrc) {
|
||||
/* the file was inserted */
|
||||
img->file_count++;
|
||||
} else {
|
||||
/* the file was already on the tree */
|
||||
free(fsrc);
|
||||
}
|
||||
*src = inserted;
|
||||
*src = *inserted;
|
||||
}
|
||||
return ISO_SUCCESS;
|
||||
}
|
||||
|
@ -14,8 +14,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct Iso_File_Src IsoFileSrc;
|
||||
|
||||
struct Iso_File_Src {
|
||||
|
||||
/* key */
|
||||
|
Loading…
Reference in New Issue
Block a user