]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: fix scols_line_move_cells() n+1 error [asan]
authorKarel Zak <kzak@redhat.com>
Mon, 18 Sep 2017 08:41:20 +0000 (10:41 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 18 Sep 2017 08:41:20 +0000 (10:41 +0200)
Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/line.c

index c2a991c2d49f61bf617e91d25806d55d20fab73f..6c64e7f620e2a952aba9b5a30b278462291338bd 100644 (file)
@@ -163,12 +163,12 @@ int scols_line_move_cells(struct libscols_line *ln, size_t newn, size_t oldn)
        /* remove old possition (move data behind oldn to oldn) */
        if (oldn + 1 < ln->ncells)
                memmove(ln->cells + oldn, ln->cells + oldn + 1,
-                       (ln->ncells - oldn) * sizeof(struct libscols_cell));
+                       (ln->ncells - oldn - 1) * sizeof(struct libscols_cell));
 
        /* create a space for new position */
        if (newn + 1 < ln->ncells)
                memmove(ln->cells + newn + 1, ln->cells + newn,
-                       (ln->ncells - newn) * sizeof(struct libscols_cell));
+                       (ln->ncells - newn - 1) * sizeof(struct libscols_cell));
 
        /* copy original data to new position */
        memcpy(&ln->cells[newn], &ce, sizeof(struct libscols_cell));