dect
/
asterisk
Archived
13
0
Fork 0

Fix off-by-one issue with sort (bug #5459)

git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6816 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
markster 2005-10-18 16:48:19 +00:00
parent be40e92107
commit 03ab019888
1 changed files with 6 additions and 6 deletions

View File

@ -93,7 +93,7 @@ static int sort_subroutine(const void *arg1, const void *arg2)
static int sort_internal(struct ast_channel *chan, char *data, char *buffer, size_t buflen)
{
char *strings, *ptrkey, *ptrvalue;
int count=1, count2;
int count=1, count2, element_count=0;
struct sortable_keys *sortable_keys;
memset(buffer, 0, buflen);
@ -139,13 +139,13 @@ static int sort_internal(struct ast_channel *chan, char *data, char *buffer, siz
qsort(sortable_keys, count, sizeof(struct sortable_keys), sort_subroutine);
for (count2 = 0; count2 < count; count2++) {
strncat(buffer + strlen(buffer), sortable_keys[count2].key, buflen - strlen(buffer));
strncat(buffer + strlen(buffer), ",", buflen - strlen(buffer));
int blen = strlen(buffer);
if (element_count++) {
strncat(buffer + blen, ",", buflen - blen - 1);
}
strncat(buffer + blen + 1, sortable_keys[count2].key, buflen - blen - 2);
}
/* Remove trailing comma */
buffer[strlen(buffer) - 1] = '\0';
return 0;
}