From 1688eabbfd90ad1c22ccb7c28bc47e0fffc7b27c Mon Sep 17 00:00:00 2001 From: Alan C Francis Date: Sun, 31 Dec 2023 20:39:51 +0000 Subject: [PATCH] fix stringarrayjoin --- containers/stringarray.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/containers/stringarray.c b/containers/stringarray.c index 846a01b..1e7dcfb 100644 --- a/containers/stringarray.c +++ b/containers/stringarray.c @@ -47,22 +47,22 @@ STRPTR StringArrayJoinedParts(StringArray array, BYTE linkCharacter, ULONG start ULONG index = 0; ULONG cursor = 0; STRPTR result = NULL; - ULONG howManyParts = MIN(maxParts, SizeOfArray(array)); + ULONG lastIndex = MIN(startIndex+maxParts, SizeOfArray(array)-1); - if( howManyParts <= 0 ) + if( lastIndex-startIndex < 0 ) { return (STRPTR)AllocVec(1, MEMF_CLEAR); //return an empty string } - for( index = startIndex; index < howManyParts; index++ ) + for( index = startIndex; index < lastIndex; index++ ) { requiredSize += strlen(StringArrayValues(array)[index]); } - requiredSize += (howManyParts - 1); // add the joins + requiredSize += (maxParts == 0 ? 0 : maxParts - 1); // add the join characters requiredSize += 1; // trailing NULL result = AllocVec(requiredSize, MEMF_CLEAR); - for( index = startIndex; index < howManyParts; index++ ) + for( index = startIndex; index < lastIndex; index++ ) { CONST_STRPTR entry = StringArrayValues(array)[index]; CopyMem((STRPTR)entry, result+cursor, strlen(entry));