Ignore:
Timestamp:
Sep 25, 2015, 8:55:01 AM (4 years ago)
Author:
cameron
Message:

Fix segfaults at page boundary

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/do_grep.cpp

    r4790 r4792  
    267267    //Final Partial Block (may be empty, but there could be carries pending).
    268268   
     269   
    269270    const auto EOF_mask = bitblock::srl(simd<1>::constant<1>(), convert(BLOCK_SIZE - remaining));
    270271   
    271     s2p_do_final_block(reinterpret_cast<BytePack *>(mFileBuffer + (blk * BLOCK_SIZE) + (segment * SEGMENT_SIZE)), basis_bits, EOF_mask);
     272    if (remaining == 0) {  // No data, we may be at a page boundary.   Do not access memory.
     273        basis_bits.bit_0 = simd<1>::constant<0>();
     274        basis_bits.bit_1 = simd<1>::constant<0>();
     275        basis_bits.bit_2 = simd<1>::constant<0>();
     276        basis_bits.bit_3 = simd<1>::constant<0>();
     277        basis_bits.bit_4 = simd<1>::constant<0>();
     278        basis_bits.bit_5 = simd<1>::constant<0>();
     279        basis_bits.bit_6 = simd<1>::constant<0>();
     280        basis_bits.bit_7 = simd<1>::constant<0>();
     281    }
     282    else { // At least 1 byte, so we are not at a page boundary yet, safe to access a full block.
     283        s2p_do_final_block(reinterpret_cast<BytePack *>(mFileBuffer + (blk * BLOCK_SIZE) + (segment * SEGMENT_SIZE)), basis_bits, EOF_mask);
     284    }
    272285
    273286    if (finalLineIsUnterminated()) {
Note: See TracChangeset for help on using the changeset viewer.