* replaced and an argument is not used more than once.
*/
-/*
- * PBYTE(lp, c) - put byte 'c' at position 'lp'
- */
-#define PBYTE(lp, c) (*(ml_get_buf(curbuf, (lp).lnum, TRUE) + (lp).col) = (c))
-
/*
* Position comparisons
*/
static void shift_block(oparg_T *oap, int amount);
static void mb_adjust_opend(oparg_T *oap);
static int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1);
+static void pbyte(pos_T lp, int c);
+#define PBYTE(lp, c) pbyte(lp, c)
+
// Flags for third item in "opchars".
#define OPF_LINES 1 // operator always works on lines
restore_lbr(lbr_saved);
#endif
}
+
+// put byte 'c' at position 'lp', but
+// verify, that the position to place
+// is actually safe
+ static void
+pbyte(pos_T lp, int c)
+{
+ char_u *p = ml_get_buf(curbuf, lp.lnum, TRUE);
+ int len = curbuf->b_ml.ml_line_len;
+
+ // safety check
+ if (lp.col >= len)
+ lp.col = (len > 1 ? len - 2 : 0);
+ *(p + lp.col) = c;
+}