From 83fa6b3bcb0276e0b122664764c815af5f9ad907 Mon Sep 17 00:00:00 2001 From: xaedes Date: Mon, 1 May 2023 14:42:44 +0200 Subject: [PATCH] fix ggml_compute_forward_dup_same_cont for when nelements < nthreads when more threads are used than elements exist ie1 was less than ie0, resulting in invalid negative byte count argument in memcpy --- ggml.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ggml.c b/ggml.c index c82ed75ac..c1f7d0441 100644 --- a/ggml.c +++ b/ggml.c @@ -6662,10 +6662,12 @@ static void ggml_compute_forward_dup_same_cont( const int ie0 = dr * ith; const int ie1 = MIN(ie0 + dr, ne); - memcpy( - ((char *) dst->data + ie0*nb0), - ((char *) src0->data + ie0*nb00), - (ie1 - ie0) * GGML_TYPE_SIZE[src0->type]); + if (ie0 < ie1) { + memcpy( + ((char *) dst->data + ie0*nb0), + ((char *) src0->data + ie0*nb00), + (ie1 - ie0) * GGML_TYPE_SIZE[src0->type]); + } } static void ggml_compute_forward_dup_f16(