From 8d93662b406c19c841eec0af82ec9737128146e4 Mon Sep 17 00:00:00 2001 From: Daniel Richtmann Date: Mon, 12 Sep 2016 13:58:01 +0200 Subject: [PATCH] Fix bug with crash when doing large allocations While trying to run a chroma job with a very large local volume I got a crash due to allocation failure. I tracked this down and the error comes from integer overflow. Using a normal int instead of size_t for holding the size of an allocation is not the best idea. This commit changes that. --- include/tables_parscalar.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/tables_parscalar.h b/include/tables_parscalar.h index 3c1fe2c..505cf12 100644 --- a/include/tables_parscalar.h +++ b/include/tables_parscalar.h @@ -252,13 +252,13 @@ namespace CPlusPlusWilsonDslash { This is the size of one of the Chi-s either forward or backward. The factor of 4 is the 4 Mu directions The second factor of 4 is for the 4 types.*/ - int chisize = sizeof(HalfSpinor)*subgrid_vol_cb*4*Nd; + size_t chisize = sizeof(HalfSpinor)*subgrid_vol_cb*4*Nd; /* Total amount: 2 x offset -- for the comms. 2 x chisize -- for the half spinor temps (2 cb's) 10*CacheCacheLine - 5 lines of padding between comms bufs and chi1, and chi1 and chi2 */ - int total_allocate = 2*chisize+2*offset+10*Cache::CacheLineSize; + size_t total_allocate = 2*chisize+2*offset+10*Cache::CacheLineSize; if(xchi == 0) { if ((xchi = QMP_allocate_aligned_memory(total_allocate,Cache::CacheSetSize,0)) == 0) {