[Asterisk-cvs] asterisk/apps app_cut.c,1.13,1.14
markster
markster
Tue Oct 18 12:54:26 CDT 2005
Update of /usr/cvsroot/asterisk/apps
In directory mongoose.digium.com:/tmp/cvs-serv6743/apps
Modified Files:
app_cut.c
Log Message:
Fix off-by-one issue with sort (bug #5459)
Index: app_cut.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_cut.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- app_cut.c 15 Sep 2005 15:44:26 -0000 1.13
+++ app_cut.c 18 Oct 2005 16:48:19 -0000 1.14
@@ -93,7 +93,7 @@
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 @@
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;
}
More information about the svn-commits
mailing list