aboutsummaryrefslogtreecommitdiff
path: root/src/libmtp.c
diff options
context:
space:
mode:
authorLinus Walleij <triad@df.lth.se>2011-03-04 20:27:03 +0100
committerLinus Walleij <triad@df.lth.se>2011-03-04 20:27:03 +0100
commit366dd1cbc323439803aa68af5f477a09c309e838 (patch)
tree3f817dd9fed71108bdc35a04ac0caa085c8b1ac1 /src/libmtp.c
parentf46d7d927d526b68c18e70773d8ebaa59acead1a (diff)
downloadlibmtp-366dd1cbc323439803aa68af5f477a09c309e838.tar.gz
Fix bug in get_files_uncached() - it didn't handle the case where
an already populated list was sent in. Bug found by Jonas Salling. Signed-off-by: Jonas Salling <jonas@salling.com> Signed-off-by: Linus Walleij <triad@df.lth.se>
Diffstat (limited to 'src/libmtp.c')
-rw-r--r--src/libmtp.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/libmtp.c b/src/libmtp.c
index f53c559..6166aeb 100644
--- a/src/libmtp.c
+++ b/src/libmtp.c
@@ -4054,12 +4054,20 @@ static LIBMTP_file_t * get_files_uncached(LIBMTP_mtpdevice_t *device,
PTPParams *params,
uint32_t storageid,
uint32_t parentId,
- LIBMTP_file_t *retfiles)
+ LIBMTP_file_t *filelist)
{
int i = 0;
- LIBMTP_file_t *curfile = NULL;
+ LIBMTP_file_t *retfiles = filelist;
+ LIBMTP_file_t *curfile = filelist;
PTPObjectHandles currentHandles;
+ // Make curfile point to the last file in the retfiles list
+ if( curfile != NULL ) {
+ while( curfile->next != NULL ) {
+ curfile = curfile->next;
+ }
+ }
+
uint16_t ret = ptp_getobjecthandles(params,
storageid,
PTP_GOH_ALL_FORMATS,
@@ -4083,8 +4091,7 @@ static LIBMTP_file_t * get_files_uncached(LIBMTP_mtpdevice_t *device,
continue;
// Add track to a list that will be returned afterwards.
- if (retfiles == NULL) {
- retfiles = file;
+ if (curfile == NULL) {
curfile = file;
} else {
curfile->next = file;
@@ -4094,11 +4101,13 @@ static LIBMTP_file_t * get_files_uncached(LIBMTP_mtpdevice_t *device,
free(currentHandles.Handler);
+ // Return a pointer to the original first file
+ // in the big list.
return retfiles;
}
/**
- * This function retrieves the content of a folder with id - parentId.
+ * This function retrieves the contents of a folder with id parent.
* The result contains both files and folders.
* The device used with this operations must have been opened with
* LIBMTP_Open_Raw_Device_Uncached() or it will fail.