Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LAGraph: Use memmove when condensing array Tj. #473

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions LAGraph/src/algorithm/LG_CC_FastSV6.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
// G->A will then become a truly read-only object (assuming GrB_wait (G->A)
// has been done first).

#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>

#define LG_FREE_ALL ;
#include "LG_internal.h"

Expand Down Expand Up @@ -604,18 +607,16 @@ int LG_CC_FastSV6 // SuiteSparse:GraphBLAS method, with GxB extensions
nvals = 0 ;
for (tid = 0 ; tid < nthreads ; tid++)
{

// this memcpy is not safe (src/dest can overlap)
// memcpy (Tj + nvals, Tj + Tp [range [tid]],
// sizeof (GrB_Index) * count [tid]) ;

// use a for loop instead
GrB_Index *Tj_dest = Tj + nvals ;
GrB_Index *Tj_src = Tj + Tp [range [tid]] ;
for (int64_t k = 0 ; k < count [tid] ; k++)
{
Tj_dest [k] = Tj_src [k] ;
}
// `memcpy` is not safe if src/dest are overlapping.
// Use `memmove` (or if available `memmove_s`) instead.

#if defined (__STDC_LIB_EXT1__)
memmove_s (Tj + nvals, Tj_size - sizeof (GrB_Index) * nvals,
Tj + Tp [range [tid]], sizeof (GrB_Index) * count [tid]) ;
#else
memmove (Tj + nvals,
Tj + Tp [range [tid]], sizeof (GrB_Index) * count [tid]) ;
#endif

nvals += count [tid] ;
count [tid] = nvals - count [tid] ;
Expand Down