Hi,

It appears to me there's a bug at least in three Palm OS SDK examples 
(ToDo, Address and Datebook).
Could somebody confirm whether I'm right when I think so?

The bug is in the functions for importing v-cards. In few words, the 
error is in wrong record index for DmRecordInfo call when imported UID 
should be "obeyed" and the record with that UID already exists. As it is 
commented in the original code, removing old record could move the new 
one. But just after the code that removes the record, there's 
DmRecordInfo call to get the UID, that uses indexNew value that can 
become wrong due to old record removal (when the new record position is 
after the old one) i.e. it can point to the next record after the new, 
or even "out of bounds" when the new record is the last - actually 
that's how I discovered the error.

Consider ToDoImportVTodo from ToDoTransfer.c (Palm OS SDK 4.0), lines 
1121-1146:

 >
         // If uid was set then a unique id was passed to be used.
         if (uid != 0 && obeyUniqueIDs)
         {
             // We can't simply remove any old record using the unique id 
and
             // then add the new record because removing the old record 
could
             // move the new one.  So, we find any old record, change the 
new
             // record, and then remove the old one.
             indexOld = indexNew;

             // Find any record with this uid.  indexOld changes only if
             // such a record is found.
             DmFindRecordByID (dbP, uid, &indexOld);

             // Change this record to this uid.  The dirty bit is set from
             // newly making this record.
             DmSetRecordInfo(dbP, indexNew, NULL, &uid);

             // Now remove any old record.
             if (indexOld != indexNew)
             {
                 DmRemoveRecord(dbP, indexOld);
             }
         }

         // Return the unique id of the record inserted.
         DmRecordInfo(dbP, indexNew, NULL, uniqueIDP, NULL);
     }
 >

So I fixed it replacing the fragment end with the following:

 >
             // Now remove any old record.
             if (indexOld != indexNew)
             {
                 DmRemoveRecord(dbP, indexOld);
             }

             *uniquieIDP = uid;
         }
         else
             // Return the unique id of the record inserted.
             DmRecordInfo(dbP, indexNew, NULL, uniqueIDP, NULL);
 >

What do you think?

Thanks for any help,
Grigory


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to