diff options
| author | Junio C Hamano <gitster@pobox.com> | 2022-02-05 09:42:31 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2022-02-05 09:42:31 -0800 |
| commit | 66775d210960f82ff0d4f69480df51bf44ea718b (patch) | |
| tree | 994a0bd5ec8d6107ca290f56f5248882aa69e341 | |
| parent | 4bb003d539acc230fba2519a0430b5d388895131 (diff) | |
| parent | b80741e5b9c6b47a6f802ffdb0bba87357b35a9f (diff) | |
| download | git-66775d210960f82ff0d4f69480df51bf44ea718b.tar.xz | |
Merge branch 'jc/qsort-s-alignment-fix'
Fix a hand-rolled alloca() imitation that may have violated
alignment requirement of data being sorted in compatibility
implementation of qsort_s() and stable qsort().
* jc/qsort-s-alignment-fix:
stable-qsort: avoid using potentially unaligned access
compat/qsort_s.c: avoid using potentially unaligned access
| -rw-r--r-- | compat/qsort_s.c | 14 | ||||
| -rw-r--r-- | stable-qsort.c | 14 |
2 files changed, 8 insertions, 20 deletions
diff --git a/compat/qsort_s.c b/compat/qsort_s.c index 52d1f0a73d..0f7ff30f5f 100644 --- a/compat/qsort_s.c +++ b/compat/qsort_s.c @@ -49,21 +49,15 @@ int git_qsort_s(void *b, size_t n, size_t s, int (*cmp)(const void *, const void *, void *), void *ctx) { const size_t size = st_mult(n, s); - char buf[1024]; + char *tmp; if (!n) return 0; if (!b || !cmp) return -1; - if (size < sizeof(buf)) { - /* The temporary array fits on the small on-stack buffer. */ - msort_with_tmp(b, n, s, cmp, buf, ctx); - } else { - /* It's somewhat large, so malloc it. */ - char *tmp = xmalloc(size); - msort_with_tmp(b, n, s, cmp, tmp, ctx); - free(tmp); - } + tmp = xmalloc(size); + msort_with_tmp(b, n, s, cmp, tmp, ctx); + free(tmp); return 0; } diff --git a/stable-qsort.c b/stable-qsort.c index 6cbaf39f7b..7ff12467cd 100644 --- a/stable-qsort.c +++ b/stable-qsort.c @@ -48,15 +48,9 @@ void git_stable_qsort(void *b, size_t n, size_t s, int (*cmp)(const void *, const void *)) { const size_t size = st_mult(n, s); - char buf[1024]; + char *tmp; - if (size < sizeof(buf)) { - /* The temporary array fits on the small on-stack buffer. */ - msort_with_tmp(b, n, s, cmp, buf); - } else { - /* It's somewhat large, so malloc it. */ - char *tmp = xmalloc(size); - msort_with_tmp(b, n, s, cmp, tmp); - free(tmp); - } + tmp = xmalloc(size); + msort_with_tmp(b, n, s, cmp, tmp); + free(tmp); } |
