From 986ef6fecc74ec06632e7719e67a7f6755babb98 Mon Sep 17 00:00:00 2001 From: Dominik Grewe Date: Fri, 26 Jun 2015 15:49:28 +0100 Subject: [PATCH] Fix loop logic error in maskedCopy. Prevents segfault when the src tensor is empty. --- lib/TH/generic/THTensorMath.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/TH/generic/THTensorMath.c b/lib/TH/generic/THTensorMath.c index fd47f5bb..5298a59a 100644 --- a/lib/TH/generic/THTensorMath.c +++ b/lib/TH/generic/THTensorMath.c @@ -40,11 +40,11 @@ void THTensor_(maskedCopy)(THTensor *tensor, THByteTensor *mask, THTensor* src ) } else if (*mask_data == 1) { + if (cntr == nelem) + THError("Number of elements of src < number of ones in mask"); *tensor_data = *src_data; src_data++; cntr++; - if (cntr > nelem) - THError("Number of elements of src < number of ones in mask"); }); THTensor_(free)(srct); }