Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2008-03-23 22:58:54 +0300
committerIgor Sysoev <igor@sysoev.ru>2008-03-23 22:58:54 +0300
commit8634118bc82c8f9a5b43abe863edcee24aa878a8 (patch)
tree21871a6d3e05aab69fb297a94f07c289497028ef /src/core/ngx_string.c
parentf84ad941dc29028d969ea83e2ef14a8053d4e511 (diff)
use dynamically allocated buffer in ngx_sort()
Diffstat (limited to 'src/core/ngx_string.c')
-rw-r--r--src/core/ngx_string.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index acd9382dd..0ac00174f 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -1432,24 +1432,30 @@ void
ngx_sort(void *base, size_t n, size_t size,
int (*cmp)(const void *, const void *))
{
- u_char *p1, *p2;
- u_char buf[256];
+ u_char *p1, *p2, *p;
+
+ p = ngx_alloc(size, ngx_cycle->log);
+ if (p == NULL) {
+ return;
+ }
for (p1 = (u_char *) base + size;
p1 < (u_char *) base + n * size;
p1 += size)
{
- ngx_memcpy(buf, p1, size);
+ ngx_memcpy(p, p1, size);
for (p2 = p1;
- p2 > (u_char *) base && cmp(p2 - size, buf) > 0;
+ p2 > (u_char *) base && cmp(p2 - size, p) > 0;
p2 -= size)
{
ngx_memcpy(p2, p2 - size, size);
}
- ngx_memcpy(p2, buf, size);
+ ngx_memcpy(p2, p, size);
}
+
+ ngx_free(p);
}