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_
|
#define LIBISO_ECMA119_H_
|
||||||
|
|
||||||
typedef struct ecma119_image Ecma119Image;
|
typedef struct ecma119_image Ecma119Image;
|
||||||
|
typedef struct Iso_File_Src IsoFileSrc;
|
||||||
|
|
||||||
struct ecma119_image {
|
struct ecma119_image {
|
||||||
|
|
||||||
|
@ -32,7 +32,8 @@ int comp_iso_file_src(const void *n1, const void *n2)
|
|||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
/* files belong to same device in same fs */
|
/* 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
|
// Not implemented for now
|
||||||
return ISO_ERROR;
|
return ISO_ERROR;
|
||||||
} else {
|
} else {
|
||||||
IsoFileSrc *inserted;
|
IsoFileSrc **inserted;
|
||||||
|
|
||||||
size = stream->get_size(stream);
|
size = stream->get_size(stream);
|
||||||
if (size == (off_t)-1) {
|
if (size == (off_t)-1) {
|
||||||
@ -83,18 +84,18 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src)
|
|||||||
fsrc->stream = file->stream;
|
fsrc->stream = file->stream;
|
||||||
|
|
||||||
/* insert the filesrc in the tree */
|
/* 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) {
|
if (inserted == NULL) {
|
||||||
free(fsrc);
|
free(fsrc);
|
||||||
return ISO_MEM_ERROR;
|
return ISO_MEM_ERROR;
|
||||||
} else if (inserted == fsrc) {
|
} else if (*inserted == fsrc) {
|
||||||
/* the file was inserted */
|
/* the file was inserted */
|
||||||
img->file_count++;
|
img->file_count++;
|
||||||
} else {
|
} else {
|
||||||
/* the file was already on the tree */
|
/* the file was already on the tree */
|
||||||
free(fsrc);
|
free(fsrc);
|
||||||
}
|
}
|
||||||
*src = inserted;
|
*src = *inserted;
|
||||||
}
|
}
|
||||||
return ISO_SUCCESS;
|
return ISO_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef struct Iso_File_Src IsoFileSrc;
|
|
||||||
|
|
||||||
struct Iso_File_Src {
|
struct Iso_File_Src {
|
||||||
|
|
||||||
/* key */
|
/* key */
|
||||||
|
Loading…
Reference in New Issue
Block a user