summaryrefslogtreecommitdiff
path: root/src/unexpand.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-01-15 11:13:44 +0000
committerJim Meyering <jim@meyering.net>2000-01-15 11:13:44 +0000
commit4841119c1afb6b375485821df4d7f592e1840d27 (patch)
tree3b71e605cf468d931e72599478f7f221e7ea537f /src/unexpand.c
parent8c0c6b046843084a2c99384c6d5df77bf7bfedef (diff)
downloadcoreutils-4841119c1afb6b375485821df4d7f592e1840d27.tar.xz
(TAB_STOP_SENTINEL): Define.
(unexpand): Use it instead of INT_MAX. Declare column and pending to be `unsigned'. Increment pending and column counters only if column is smaller than TAB_STOP_SENTINEL.
Diffstat (limited to 'src/unexpand.c')
-rw-r--r--src/unexpand.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/unexpand.c b/src/unexpand.c
index c0749c4ed..14eecae52 100644
--- a/src/unexpand.c
+++ b/src/unexpand.c
@@ -1,5 +1,5 @@
/* unexpand - convert spaces to tabs
- Copyright (C) 89, 91, 1995-1999 Free Software Foundation, Inc.
+ Copyright (C) 89, 91, 1995-2000 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -57,6 +57,11 @@
allocated for the list of tabstops. */
#define TABLIST_BLOCK 256
+/* A sentinel value that's placed at the end of the list of tab stops.
+ This value must be a large number, but not so large that adding the
+ length of a line to it would cause the column variable to overflow. */
+#define TAB_STOP_SENTINEL INT_MAX
+
/* The name this program was run with. */
char *program_name;
@@ -219,10 +224,10 @@ unexpand (void)
/* Index in `tab_list' of next tabstop: */
int tab_index = 0; /* For calculating width of pending tabs. */
int print_tab_index = 0; /* For printing as many tabs as possible. */
- int column = 0; /* Column on screen of next char. */
+ unsigned int column = 0; /* Column on screen of next char. */
int next_tab_column; /* Column the next tab stop is on. */
int convert = 1; /* If nonzero, perform translations. */
- int pending = 0; /* Pending columns of blanks. */
+ unsigned int pending = 0; /* Pending columns of blanks. */
fp = next_file ((FILE *) NULL);
if (fp == NULL)
@@ -235,7 +240,7 @@ unexpand (void)
{
c = getc (fp);
- if (c == ' ' && convert)
+ if (c == ' ' && convert && column < TAB_STOP_SENTINEL)
{
++pending;
++column;
@@ -276,7 +281,7 @@ unexpand (void)
pending = 0;
}
column -= pending;
- while (pending != 0)
+ while (pending > 0)
{
if (tab_size == 0)
{
@@ -437,7 +442,7 @@ main (int argc, char **argv)
else
{
/* Append a sentinel to the list of tab stop indices. */
- add_tabstop (INT_MAX);
+ add_tabstop (TAB_STOP_SENTINEL);
tab_size = 0;
}