Get contact by number returns wrong index

Post Reply
OK1TE
Posts: 58
Joined: Tue Sep 29, 2020 7:58 am

Get contact by number returns wrong index

Post by OK1TE » Fri Jun 04, 2021 11:29 pm

Steps to reproduce:
- have 1 to n contacts, n >= 3
- choose m, where 1 < m < n
- remove m-th contact
- it's no longer possible to remove i-th contact, where m < i <= n -> bug

My fix:
in /firmware/source/functions/codeplug.c

Code: Select all

@@ -693,8 +693,10 @@ int codeplugDTMFContactGetDataForNumber(int number, struct_codeplugDTMFContact_t
 {
 	if ((number >= CODEPLUG_DTMF_CONTACTS_MIN) && (number <= CODEPLUG_DTMF_CONTACTS_MAX))
 	{
-		codeplugDTMFContactGetDataForIndex(codeplugContactsCache.contactsDTMFLookupCache[number - 1].index, contact);
-		return number;
+		if (codeplugDTMFContactGetDataForIndex(codeplugContactsCache.contactsDTMFLookupCache[number - 1].index, contact))
+		{
+			return codeplugContactsCache.contactsDTMFLookupCache[number - 1].index;
+		}
 	}
 
 	return 0;
@@ -716,7 +718,7 @@ int codeplugContactGetDataForNumberInType(int number, uint32_t callType, struct_
 		{
 			if (codeplugContactGetDataForIndex(codeplugContactsCache.contactsLookupCache[i].index, contact))
 			{
-				pos = i + 1;
+				pos = codeplugContactsCache.contactsLookupCache[i].index;
 				break;
 			}
 		}

VK3KYY
Posts: 7484
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Get contact by number returns wrong index

Post by VK3KYY » Sat Jun 05, 2021 10:39 pm

OK.

I will need to test and confrim the bug and the fix

User avatar
F1RMB
Posts: 2518
Joined: Sat Nov 16, 2019 5:42 am
Location: Grenoble, France

Re: Get contact by number returns wrong index

Post by F1RMB » Mon Jun 07, 2021 5:54 pm

Hi,
OK1TE wrote:
Fri Jun 04, 2021 11:29 pm
Steps to reproduce:
- have 1 to n contacts, n >= 3
- choose m, where 1 < m < n
- remove m-th contact
- it's no longer possible to remove i-th contact, where m < i <= n -> bug

My fix:
in /firmware/source/functions/codeplug.c

Code: Select all

@@ -693,8 +693,10 @@ int codeplugDTMFContactGetDataForNumber(int number, struct_codeplugDTMFContact_t
 {
 	if ((number >= CODEPLUG_DTMF_CONTACTS_MIN) && (number <= CODEPLUG_DTMF_CONTACTS_MAX))
 	{
-		codeplugDTMFContactGetDataForIndex(codeplugContactsCache.contactsDTMFLookupCache[number - 1].index, contact);
-		return number;
+		if (codeplugDTMFContactGetDataForIndex(codeplugContactsCache.contactsDTMFLookupCache[number - 1].index, contact))
+		{
+			return codeplugContactsCache.contactsDTMFLookupCache[number - 1].index;
+		}
 	}
 
 	return 0;
@@ -716,7 +718,7 @@ int codeplugContactGetDataForNumberInType(int number, uint32_t callType, struct_
 		{
 			if (codeplugContactGetDataForIndex(codeplugContactsCache.contactsLookupCache[i].index, contact))
 			{
-				pos = i + 1;
+				pos = codeplugContactsCache.contactsLookupCache[i].index;
 				break;
 			}
 		}
Okay, I've checked and indeed there's a bug. I applied that fix (with a little variation).
BTW, I also found two other little problems in the contact list, and did fix 'em.

Thank you for the report and fix.


Cheers.
---
Daniel

Post Reply