From: <ny...@us...> - 2006-12-28 17:19:12
|
Revision: 220 http://svn.sourceforge.net/pmplib/?rev=220&view=rev Author: nyaochi Date: 2006-12-28 09:19:09 -0800 (Thu, 28 Dec 2006) Log Message: ----------- Fixed a bug. Pointers might be invalid after a realloc() call. Modified Paths: -------------- trunk/pmplib/lib/pmp_iriverplus3/idx.c trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.c Modified: trunk/pmplib/lib/pmp_iriverplus3/idx.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/idx.c 2006-12-28 16:56:01 UTC (rev 219) +++ trunk/pmplib/lib/pmp_iriverplus3/idx.c 2006-12-28 17:19:09 UTC (rev 220) @@ -743,11 +743,23 @@ int type = dictbl->fields[field].type; int ret = avl_insert_key(idx->avl, &entry->fields[field], type, &offset, root); if (level+1 < IP3DBIDX_MAX_KEYLEVEL && dictbl->indices[index].fields[level+1] != -1) { + /* The following code does not work since we cannot guarantee that node->tail + * is valid after idx_insert_dat() call, which may move the memory block to + * expand it (realloc). + * avlnode_t* node = avlnode(idx->avl, offset); + * idx_insert_dat(idx, dictbl, &node->tail, entry, index, level+1); + * Therefore, we need to update node->tail after idx_insert_dat() call. + */ avlnode_t* node = avlnode(idx->avl, offset); - idx_insert_dat(idx, dictbl, &node->tail, entry, index, level+1); + uint32_t child = node->tail; + idx_insert_dat(idx, dictbl, &child, entry, index, level+1); + node = avlnode(idx->avl, offset); + node->tail = child; } else { + /* The same here. We must obtain the pointer to the node after avltail_new() call. + */ + uint32_t offset_tail = avltail_new(idx->avl); avlnode_t* node = avlnode(idx->avl, offset); - uint32_t offset_tail = avltail_new(idx->avl); avltail_t* tail = (avltail_t*)avlnode(idx->avl, offset_tail); tail->data = entry->offset; tail->next = node->tail; Modified: trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.c 2006-12-28 16:56:01 UTC (rev 219) +++ trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.c 2006-12-28 17:19:09 UTC (rev 220) @@ -65,7 +65,7 @@ "iriver_e10_ums_1.04", "E10 UMS", "UM", "1.04", "1.04", "System\\E10.SYS", "System\\db.dat", "System\\db.dic", "System\\db.idx", - "Music2\\", "Playlists\\", + "", "Playlists\\", ".plp", }, { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |