Changeset 4794


Ignore:
Timestamp:
Sep 26, 2015, 8:10:06 AM (2 years ago)
Author:
cameron
Message:

Resolve bus error issue; tag icgrep-1.00a

Location:
tags/icgrep1.0/icgrep-devel/icgrep-1.00a
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • tags/icgrep1.0/icgrep-devel/icgrep-1.00a/do_grep.cpp

    r4482 r4794  
    101101      }
    102102      else if (end_byte == 0x0D) {
    103           // Check for line_end on first byte of CRLF;  note that to safely
    104           // access past line_end, even at the end of buffer, we require the
    105           // mmap_sentinel_bytes >= 1.
    106           if (buffer[line_end + 1] == 0x0A) {
     103          // Check for line_end on first byte of CRLF;  note that we don't
     104          // want to access past the end of buffer.
     105          if ((buffer + line_end + 1 < mFileBuffer + mFileSize) && (buffer[line_end + 1] == 0x0A)) {
    107106              // Found CRLF; preserve both bytes.
    108107              line_end++;
     
    178177    }
    179178    mFileSize = infile_sb.st_size;
    180     // Set 2 sentinel bytes, 1 for possible addition of LF for unterminated last line,
    181     // 1 guard byte.  PROT_WRITE enables writing the sentinel.
    182     const size_t mmap_sentinel_bytes = 2; 
    183     mFileBuffer = (char *) mmap(NULL, mFileSize + mmap_sentinel_bytes, PROT_READ|PROT_WRITE, MAP_PRIVATE, fdSrc, 0);
     179    mFileBuffer = (char *) mmap(NULL, mFileSize, PROT_READ, MAP_PRIVATE, fdSrc, 0);
    184180    if (mFileBuffer == MAP_FAILED) {
    185181        if (errno ==  ENOMEM) {
     
    285281   
    286282    block_base = block_pos + segment_base;
    287     s2p_do_final_block((BytePack *) &mFileBuffer[block_base], basis_bits, EOF_mask);
     283    if (remaining == 0) {  // No data, we may be at a page boundary.   Do not access memory.
     284        basis_bits.bit_0 = simd<1>::constant<0>();
     285        basis_bits.bit_1 = simd<1>::constant<0>();
     286        basis_bits.bit_2 = simd<1>::constant<0>();
     287        basis_bits.bit_3 = simd<1>::constant<0>();
     288        basis_bits.bit_4 = simd<1>::constant<0>();
     289        basis_bits.bit_5 = simd<1>::constant<0>();
     290        basis_bits.bit_6 = simd<1>::constant<0>();
     291        basis_bits.bit_7 = simd<1>::constant<0>();
     292    }
     293    else { // At least 1 byte, so we are not at a page boundary yet, safe to access a full block.
     294         s2p_do_final_block((BytePack *) &mFileBuffer[block_base], basis_bits, EOF_mask);
     295    }
    288296
    289297    if (finalLineIsUnterminated()) {
     
    293301        basis_bits.bit_4 = simd_or(basis_bits.bit_4, EOF_pos);
    294302        basis_bits.bit_6 = simd_or(basis_bits.bit_6, EOF_pos);
    295         // Add final sentinel byte so write_matches knows what to do.
    296         mFileBuffer[mFileSize] = 0x0;
    297303    }
    298304   
     
    325331    }
    326332   
    327     munmap((void *) mFileBuffer, mFileSize + mmap_sentinel_bytes);
     333    munmap((void *) mFileBuffer, mFileSize);
    328334    close(fdSrc);
    329335   
Note: See TracChangeset for help on using the changeset viewer.