Mes C Library: stdlib/qsort.c: Fix qswap segfault.
* stdlib/qsort.c (qswap): Remove hard coded buffer size. Allow swapping of objects of arbitrary size.
This commit is contained in:
parent
d3a039949b
commit
4492173466
|
@ -1,6 +1,7 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
* Copyright © 2021 Paul Dersey <pdersey@gmail.com>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
*
|
*
|
||||||
|
@ -24,10 +25,14 @@
|
||||||
void
|
void
|
||||||
qswap (void *a, void *b, size_t size)
|
qswap (void *a, void *b, size_t size)
|
||||||
{
|
{
|
||||||
char *buf[8];
|
char *pa = a;
|
||||||
memcpy (buf, a, size);
|
char *pb = b;
|
||||||
memcpy (a, b, size);
|
do
|
||||||
memcpy (b, buf, size);
|
{
|
||||||
|
char tmp = *pa;
|
||||||
|
*pa++ = *pb;
|
||||||
|
*pb++ = tmp;
|
||||||
|
} while (--size > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
|
|
Loading…
Reference in a new issue