From 52248c2a93d8e7f281511728f235b852882cfc6c Mon Sep 17 00:00:00 2001 From: Pankaj Singh Date: Mon, 28 Oct 2024 12:05:50 -0700 Subject: [PATCH] add validity check AlignedTableTightAlloc clear method (#3997) Summary: Avoid null pointer error by checking that `numel > 0`. It's equivalent of checking`ptr != null` but keeping numel check for consistency. Bug reported in: https://github.com/facebookresearch/faiss/issues/3994 Reviewed By: mnorris11 Differential Revision: D65073502 --- faiss/utils/AlignedTable.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/faiss/utils/AlignedTable.h b/faiss/utils/AlignedTable.h index f570797a01..216dae01fc 100644 --- a/faiss/utils/AlignedTable.h +++ b/faiss/utils/AlignedTable.h @@ -63,7 +63,9 @@ struct AlignedTableTightAlloc { } void clear() { - memset(ptr, 0, nbytes()); + if (numel > 0) { + memset(ptr, 0, nbytes()); + } } size_t size() const { return numel;