Browse code

msrp: proper cmap insert when last item has greater citemid

- condition for last item was processed first, resulting in improper
order of items, GH #3215

Daniel-Constantin Mierla authored on 16/08/2022 07:09:45
Showing 1 changed files
... ...
@@ -270,20 +270,21 @@ int msrp_cmap_save(msrp_frame_t *mf)
270 270
 	} else {
271 271
 		for(itb=_msrp_cmap_head->cslots[idx].first; itb; itb=itb->next)
272 272
 		{
273
-			if(itb->citemid>it->citemid || itb->next==NULL) {
274
-				if(itb->next==NULL) {
275
-					itb->next=it;
276
-					it->prev = itb;
273
+			if(itb->citemid>it->citemid) {
274
+				/* insert before current item */
275
+				it->next = itb;
276
+				if(itb->prev==NULL) {
277
+					_msrp_cmap_head->cslots[idx].first = it;
277 278
 				} else {
278
-					it->next = itb;
279
-					if(itb->prev==NULL) {
280
-						_msrp_cmap_head->cslots[idx].first = it;
281
-					} else {
282
-						itb->prev->next = it;
283
-					}
284
-					it->prev = itb->prev;
285
-					itb->prev = it;
279
+					itb->prev->next = it;
286 280
 				}
281
+				it->prev = itb->prev;
282
+				itb->prev = it;
283
+				break;
284
+			} else if(itb->next==NULL) {
285
+				/* insert after last item */
286
+				itb->next=it;
287
+				it->prev = itb;
287 288
 				break;
288 289
 			}
289 290
 		}