Changeset 4800


Ignore:
Timestamp:
Sep 27, 2015, 2:55:58 PM (2 years ago)
Author:
cameron
Message:

Revert do_grep to r4795

File:
1 edited

Legend:

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

    r4797 r4800  
    7070            mLineNum++;
    7171        }
    72         assert (buffer + line_end < mFileBuffer + mFileSize);
    7372        if (mShowFileNameOption) {
    7473            out << mFileName << ':';
     
    7877        }
    7978        if ((buffer[line_start] == 0xA) && (line_start != line_end)) {
    80             // The LF of a CRLF.  Really the end of the last line.
     79            // The line "starts" on the LF of a CRLF.  Really the end of the last line.
    8180            line_start++;
     81        }
     82        if (buffer + line_end == mFileBuffer + mFileSize) {
     83            // The match position is at end-of-file.   We have a final unterminated line.
     84            out.write(&buffer[line_start], line_end - line_start);
     85            if (mNormalizeLineBreaksOption) {
     86              out << '\n';  // terminate it
     87            }
     88            return line_end;
    8289        }
    8390        unsigned char end_byte = (unsigned char)buffer[line_end];
     
    94101        }
    95102        else {
    96             if (end_byte == 0x0) {
    97                 // This must be a sentinel byte position at the end of file.
    98                 // Do not write it.
    99                 line_end--;
    100             } else if (end_byte == 0x0D) {
     103            if (end_byte == 0x0D) {
    101104                // Check for line_end on first byte of CRLF;  note that we don't
    102105                // want to access past the end of buffer.
     
    267270    //Final Partial Block (may be empty, but there could be carries pending).
    268271   
     272   
    269273    const auto EOF_mask = bitblock::srl(simd<1>::constant<1>(), convert(BLOCK_SIZE - remaining));
    270274   
    271     s2p_do_final_block(reinterpret_cast<BytePack *>(mFileBuffer + (blk * BLOCK_SIZE) + (segment * SEGMENT_SIZE)), basis_bits, EOF_mask);
     275    if (remaining == 0) {  // No data, we may be at a page boundary.   Do not access memory.
     276        basis_bits.bit_0 = simd<1>::constant<0>();
     277        basis_bits.bit_1 = simd<1>::constant<0>();
     278        basis_bits.bit_2 = simd<1>::constant<0>();
     279        basis_bits.bit_3 = simd<1>::constant<0>();
     280        basis_bits.bit_4 = simd<1>::constant<0>();
     281        basis_bits.bit_5 = simd<1>::constant<0>();
     282        basis_bits.bit_6 = simd<1>::constant<0>();
     283        basis_bits.bit_7 = simd<1>::constant<0>();
     284    }
     285    else { // At least 1 byte, so we are not at a page boundary yet, safe to access a full block.
     286        s2p_do_final_block(reinterpret_cast<BytePack *>(mFileBuffer + (blk * BLOCK_SIZE) + (segment * SEGMENT_SIZE)), basis_bits, EOF_mask);
     287    }
    272288
    273289    if (finalLineIsUnterminated()) {
Note: See TracChangeset for help on using the changeset viewer.