From aa312cf7d73c171426eb07d9ae04749e0038ba06 Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Date: Sat, 15 Dec 2007 16:48:50 +0100 Subject: [PATCH] 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! --- src/ecma119.h | 1 + src/filesrc.c | 11 ++++++----- src/filesrc.h | 2 -- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ecma119.h b/src/ecma119.h index 7a97447..8b3f10a 100644 --- a/src/ecma119.h +++ b/src/ecma119.h @@ -10,6 +10,7 @@ #define LIBISO_ECMA119_H_ typedef struct ecma119_image Ecma119Image; +typedef struct Iso_File_Src IsoFileSrc; struct ecma119_image { diff --git a/src/filesrc.c b/src/filesrc.c index 6219781..12281dd 100644 --- a/src/filesrc.c +++ b/src/filesrc.c @@ -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; } diff --git a/src/filesrc.h b/src/filesrc.h index 63e541e..176c755 100644 --- a/src/filesrc.h +++ b/src/filesrc.h @@ -14,8 +14,6 @@ #include -typedef struct Iso_File_Src IsoFileSrc; - struct Iso_File_Src { /* key */