Merge branch 'colcrt' of git://github.com/kerolasa/lelux-utiliteetit

* 'colcrt' of git://github.com/kerolasa/lelux-utiliteetit:
  tests: add colcrt regression tests
  colcrt: allocate enough space for data moves [afl & asan]
  colcrt: avoid writing beyond array bound [afl & asan]
  colcrt: use #define in place of magic constants
  misc: fix redundant assignment and reassignments before use [cppcheck]
  tools: stop checkmans.sh validating libtool builds
This commit is contained in:
Karel Zak 2015-08-12 22:53:47 +02:00
commit 2279ab60ba
11 changed files with 442 additions and 15 deletions

View File

@ -103,7 +103,7 @@ char *proc_get_command(pid_t pid)
char buf[BUFSIZ], *res = NULL;
ssize_t sz = 0;
size_t i;
int fd = -1;
int fd;
snprintf(buf, sizeof(buf), "/proc/%d/cmdline", (int) pid);
fd = open(buf, O_RDONLY);

View File

@ -185,7 +185,7 @@ int main(int argc, char **argv)
stats[0] = range[0], stats[1] = 0;
gettime_monotonic(&last);
for (range[0] = range[0]; range[0] < end; range[0] += range[1]) {
for (/* nothing */; range[0] < end; range[0] += range[1]) {
if (range[0] + range[1] > end)
range[1] = end - range[0];

View File

@ -60,7 +60,7 @@ struct fstrim_range {
static int fstrim_filesystem(const char *path, struct fstrim_range *rangetpl,
int verbose)
{
int fd = -1, rc;
int fd, rc;
struct stat sb;
struct fstrim_range range;

View File

@ -37,6 +37,7 @@ TS_CMD_DELPART=${TS_CMD_DELPART:-"$top_builddir/delpart"}
TS_CMD_BLKDISCARD=${TS_CMD_BLKID-"$top_builddir/blkdiscard"}
TS_CMD_BLKID=${TS_CMD_BLKID-"$top_builddir/blkid"}
TS_CMD_CAL=${TS_CMD_CAL-"$top_builddir/cal"}
TS_CMD_COLCRT=${TS_CMD_COLCRT:-"$top_builddir/colcrt"}
TS_CMD_COLRM=${TS_CMD_COLRM:-"$top_builddir/colrm"}
TS_CMD_COL=${TS_CMD_COL:-"$top_builddir/col"}
TS_CMD_COLUMN=${TS_CMD_COLUMN:-"$top_builddir/column"}

View File

@ -0,0 +1 @@
return value: 0

View File

@ -0,0 +1,386 @@
FGHIKIJKN\|
MN9|
XYZRnT RnTUV| NXP:w|
MN
'QRnTUVWXYZQRnTU|
MN9|
|
return value: 0

BIN
tests/ts/colcrt/crash1 Normal file

Binary file not shown.

BIN
tests/ts/colcrt/crash2 Normal file

Binary file not shown.

34
tests/ts/colcrt/regressions Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
#
# This file is part of util-linux.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
TS_TOPDIR="${0%/*}/../.."
TS_DESC="regressions"
. $TS_TOPDIR/functions.sh
ts_init "$*"
ts_check_test_command "$TS_CMD_COLCRT"
check_input_file() {
ts_init_subtest ${1##*/}
$TS_CMD_COLCRT < $1 > $TS_OUTPUT 2>&1
echo "return value: $?" >> $TS_OUTPUT
ts_finalize_subtest
}
check_input_file "$TS_SELF/crash1"
check_input_file "$TS_SELF/crash2"
ts_finalize

View File

@ -68,7 +68,10 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out);
* Option -2 forces printing of all half lines.
*/
wchar_t page[267][132];
#define FLUSH_SIZE 62
#define PAGE_ARRAY_ROWS 267
#define PAGE_ARRAY_COLS 132
wchar_t page[PAGE_ARRAY_ROWS + 1][PAGE_ARRAY_COLS + 1];
int outline = 1;
int outcol;
@ -158,8 +161,8 @@ void colcrt(FILE *f) {
}
switch (c) {
case '\n':
if (outline >= 265)
pflush(62);
if (outline >= (PAGE_ARRAY_ROWS - 2))
pflush(FLUSH_SIZE);
outline += 2;
outcol = 0;
continue;
@ -170,8 +173,8 @@ void colcrt(FILE *f) {
c = getwc(f);
switch (c) {
case '9':
if (outline >= 266)
pflush(62);
if (outline >= (PAGE_ARRAY_ROWS - 1))
pflush(FLUSH_SIZE);
outline++;
continue;
case '8':
@ -198,7 +201,9 @@ void colcrt(FILE *f) {
/* fallthrough */
default:
w = wcwidth(c);
if (outcol + w > 132) {
if (w < 0)
continue;
if (outcol + w > PAGE_ARRAY_COLS) {
outcol++;
continue;
}
@ -207,7 +212,7 @@ void colcrt(FILE *f) {
if (c == '_') {
if (suppresul)
continue;
cp += 132;
cp += PAGE_ARRAY_COLS;
c = '-';
}
if (*cp == 0) {
@ -250,8 +255,8 @@ void pflush(int ol)
l = ol;
lastomit = 0;
if (l > 266)
l = 266;
if (l > (PAGE_ARRAY_ROWS - 1))
l = PAGE_ARRAY_ROWS - 1;
else
l |= 1;
for (i = first | 1; i < l; i++) {
@ -274,8 +279,8 @@ void pflush(int ol)
}
putwchar('\n');
}
memmove(page, page[ol], (267 - ol) * 132 * sizeof(wchar_t));
memset(page[267 - ol], '\0', ol * 132 * sizeof(wchar_t));
memmove(page, page[ol], (PAGE_ARRAY_ROWS - ol) * PAGE_ARRAY_COLS * sizeof(wchar_t));
memset(page[PAGE_ARRAY_ROWS - ol], '\0', ol * PAGE_ARRAY_COLS * sizeof(wchar_t));
outline -= ol;
outcol = 0;
first = 1;

View File

@ -70,7 +70,7 @@ remove_repeats()
cd $(git rev-parse --show-toplevel)
for I in $(
find -path './autom4te.cache' -prune -o -name '*[[:alpha:]].[1-8]' -print
find -path './autom4te.cache' -prune -o -path './.libs' -prune -o -name '*[[:alpha:]].[1-8]' -print
); do
MAN_FILE=${I##*/}
MAN_LIST[${MAN_FILE%%.[0-9]}]=1