To: vim-dev@vim.org Subject: Patch 6.1.293 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.293 Problem: byte2line() returns a wrong result for some values. Solution: Change ">=" to ">" in ml_find_line_or_offset(). (Bradford C Smith) Add one to the line number when at the end of a block. Files: src/memline.c *** ../vim61.292/src/memline.c Tue Apr 30 16:50:20 2002 --- src/memline.c Sun Jan 19 16:44:22 2003 *************** *** 4236,4241 **** --- 4238,4244 ---- long offset; int len; int ffdos = (get_fileformat(buf) == EOL_DOS); + int extra = 0; if (buf->b_ml.ml_usedchunks == -1 || buf->b_ml.ml_chunksize == NULL *************** *** 4255,4264 **** curline = 1; curix = size = 0; while (curix < buf->b_ml.ml_usedchunks - 1 ! && ((line && line >= curline + buf->b_ml.ml_chunksize[curix].mlcs_numlines) ! || (offset ! && offset >= size + buf->b_ml.ml_chunksize[curix].mlcs_totalsize + ffdos * buf->b_ml.ml_chunksize[curix].mlcs_numlines))) { curline += buf->b_ml.ml_chunksize[curix].mlcs_numlines; --- 4258,4267 ---- curline = 1; curix = size = 0; while (curix < buf->b_ml.ml_usedchunks - 1 ! && ((line != 0 && line >= curline + buf->b_ml.ml_chunksize[curix].mlcs_numlines) ! || (offset != 0 ! && offset > size + buf->b_ml.ml_chunksize[curix].mlcs_totalsize + ffdos * buf->b_ml.ml_chunksize[curix].mlcs_numlines))) { curline += buf->b_ml.ml_chunksize[curix].mlcs_numlines; *************** *** 4268,4280 **** curix++; } ! while ((line && curline < line) || (offset && size < offset)) { if (curline > buf->b_ml.ml_line_count || (hp = ml_find_line(buf, curline, ML_FIND)) == NULL) - { return -1; - } dp = (DATA_BL *)(hp->bh_data); count = (long)(buf->b_ml.ml_locked_high) - (long)(buf->b_ml.ml_locked_low) + 1; --- 4271,4281 ---- curix++; } ! while ((line != 0 && curline < line) || (offset != 0 && size < offset)) { if (curline > buf->b_ml.ml_line_count || (hp = ml_find_line(buf, curline, ML_FIND)) == NULL) return -1; dp = (DATA_BL *)(hp->bh_data); count = (long)(buf->b_ml.ml_locked_high) - (long)(buf->b_ml.ml_locked_low) + 1; *************** *** 4284,4290 **** else text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); /* Compute index of last line to use in this MEMLINE */ ! if (line) { if (curline + (count - idx) >= line) idx += line - curline - 1; --- 4285,4291 ---- else text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); /* Compute index of last line to use in this MEMLINE */ ! if (line != 0) { if (curline + (count - idx) >= line) idx += line - curline - 1; *************** *** 4293,4298 **** --- 4294,4300 ---- } else { + extra = 0; while (offset >= size + text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK) + ffdos) *************** *** 4300,4312 **** if (ffdos) size++; if (idx == count - 1) break; idx++; } } len = text_end - ((dp->db_index[idx]) & DB_INDEX_MASK); size += len; ! if (offp != NULL && size >= offset) { if (size + ffdos == offset) *offp = 0; --- 4302,4317 ---- if (ffdos) size++; if (idx == count - 1) + { + extra = 1; break; + } idx++; } } len = text_end - ((dp->db_index[idx]) & DB_INDEX_MASK); size += len; ! if (offset != 0 && size >= offset) { if (size + ffdos == offset) *offp = 0; *************** *** 4315,4321 **** else *offp = offset - size + len - (text_end - ((dp->db_index[idx - 1]) & DB_INDEX_MASK)); ! return curline + idx - start_idx; } curline = buf->b_ml.ml_locked_high + 1; } --- 4320,4326 ---- else *offp = offset - size + len - (text_end - ((dp->db_index[idx - 1]) & DB_INDEX_MASK)); ! return curline + idx - start_idx + extra; } curline = buf->b_ml.ml_locked_high + 1; } *************** *** 4355,4361 **** check_cursor(); # ifdef FEAT_MBYTE ! /* prevent cursor from moving on the trail byte */ if (has_mbyte) mb_adjust_cursor(); # endif --- 4360,4366 ---- check_cursor(); # ifdef FEAT_MBYTE ! /* Make sure the cursor is on the first byte of a multi-byte char. */ if (has_mbyte) mb_adjust_cursor(); # endif *** ../vim61.292/src/version.c Sun Jan 19 16:13:04 2003 --- src/version.c Sun Jan 19 16:47:46 2003 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 293, /**/ -- I used to be indecisive, now I'm not sure. /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.Moolenaar.net \\\ /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///