diff options
author | ache <ache@FreeBSD.org> | 2002-04-07 00:49:00 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2002-04-07 00:49:00 +0000 |
commit | 1787bef03c953feb647434bb2946b724c1c986c7 (patch) | |
tree | 70e25a2ed6c5ebfc8ca94c6ead437be0e9fd2ea8 /contrib/sort | |
parent | da0af9e1df62214aae642b6a081723b66c7a4e73 (diff) | |
download | FreeBSD-src-1787bef03c953feb647434bb2946b724c1c986c7.zip FreeBSD-src-1787bef03c953feb647434bb2946b724c1c986c7.tar.gz |
Original code bugfixed. This NOT touch old sorting order a bit.
1) Remove \n from COPYRIGHT macro to shut up assembler warning
2) Fix struct sigaction initialization (arguments swap)
3) Fix out of bounds negative indexing for -R arg > 127
4) Remove doubled initialization of vars already initialized statically
5) Convert ctype macros char arg to u_char to prevents sign extension
Diffstat (limited to 'contrib/sort')
-rw-r--r-- | contrib/sort/init.c | 14 | ||||
-rw-r--r-- | contrib/sort/sort.c | 12 |
2 files changed, 14 insertions, 12 deletions
diff --git a/contrib/sort/init.c b/contrib/sort/init.c index 3f5c068..0d97ff8 100644 --- a/contrib/sort/init.c +++ b/contrib/sort/init.c @@ -34,6 +34,8 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $FreeBSD$ */ #include "sort.h" @@ -127,7 +129,7 @@ setcolumn(pos, cur_fld, gflag) int tmp; col = cur_fld->icol.num ? (&(*cur_fld).tcol) : (&(*cur_fld).icol); pos += sscanf(pos, "%d", &(col->num)); - while (isdigit(*pos)) + while (isdigit((u_char)*pos)) pos++; if (col->num <= 0 && !(col->num == 0 && col == &(cur_fld->tcol))) errx(2, "field numbers must be positive"); @@ -136,7 +138,7 @@ setcolumn(pos, cur_fld, gflag) errx(2, "cannot indent end of line"); ++pos; pos += sscanf(pos, "%d", &(col->indent)); - while (isdigit(*pos)) + while (isdigit((u_char)*pos)) pos++; if (&cur_fld->icol == col) col->indent--; @@ -243,7 +245,7 @@ fixit(argc, argv) argv[i] = vpos; vpos += sprintf(vpos, "-k"); tpos += sscanf(tpos, "%d", &v); - while (isdigit(*tpos)) + while (isdigit((u_char)*tpos)) tpos++; vpos += sprintf(vpos, "%d", v+1); if (*tpos == '.') { @@ -255,16 +257,16 @@ fixit(argc, argv) *vpos++ = *tpos++; vpos += sprintf(vpos, ","); if (argv[i+1] && - argv[i+1][0] == '-' && isdigit(argv[i+1][1])) { + argv[i+1][0] == '-' && isdigit((u_char)argv[i+1][1])) { tpos = argv[i+1] + 1; tpos += sscanf(tpos, "%d", &w); - while (isdigit(*tpos)) + while (isdigit((u_char)*tpos)) tpos++; x = 0; if (*tpos == '.') { ++tpos; tpos += sscanf(tpos, "%d", &x); - while (isdigit(*tpos)) + while (isdigit((u_char)*tpos)) tpos++; } if (x) { diff --git a/contrib/sort/sort.c b/contrib/sort/sort.c index a119b7d..3f61406 100644 --- a/contrib/sort/sort.c +++ b/contrib/sort/sort.c @@ -34,6 +34,8 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $FreeBSD$ */ /* Sort sorts a file using an optional user-defined key. @@ -46,8 +48,7 @@ #include "pathnames.h" #ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1993\n\ - The Regents of the University of California. All rights reserved.\n"); +__COPYRIGHT("@(#) Copyright (c) 1993 The Regents of the University of California. All rights reserved."); #endif /* not lint */ #ifndef lint @@ -112,8 +113,7 @@ main(argc, argv) memset(fldtab, 0, (ND+2)*sizeof(struct field)); memset(d_mask, 0, NBINS); - d_mask[REC_D = '\n'] = REC_D_F; - SINGL_FLD = SEP_FLAG = 0; + d_mask[REC_D] = REC_D_F; d_mask['\t'] = d_mask[' '] = BLANK | FLD_D; ftpos = fldtab; many_files(); @@ -172,7 +172,7 @@ main(argc, argv) case 'R': if (REC_D != '\n') usage("multiple record delimiters"); - if ('\n' == (REC_D = *optarg)) + if ('\n' == (REC_D = (u_char)*optarg)) break; d_mask['\n'] = d_mask[' ']; d_mask[REC_D] = REC_D_F; @@ -252,7 +252,7 @@ main(argc, argv) } else if (!(ch = access(outpath, 0)) && strncmp(_PATH_DEV, outpath, 5)) { static const struct sigaction act = - { onsignal, {{0}}, SA_RESTART | SA_RESETHAND }; + { { onsignal }, SA_RESTART | SA_RESETHAND, { { 0 } } }; static const int sigtable[] = {SIGHUP, SIGINT, SIGPIPE, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF, 0}; int outfd; |