summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@apple.com>2011-04-28 00:39:17 -0700
committerJeremy Huddleston <jeremyhu@apple.com>2011-04-28 01:14:02 -0700
commite15cbb4f48a9c5c0aae5acc88a7f56086fc9e51f (patch)
treeebed060c938eb9734b9d2f81dbe7e5c6d182a18d
parenta0d43f88e563ca2fd376bbe222d4809b9976624b (diff)
bdftruncate: Properly support -w and +w
Regression introduced by fb486bb1a5038912d064291b12c7aef5da3d8b63 Found-by: clang static analyzer Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
-rw-r--r--bdftruncate.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/bdftruncate.c b/bdftruncate.c
index a527305..e2b5d87 100644
--- a/bdftruncate.c
+++ b/bdftruncate.c
@@ -43,14 +43,10 @@
static int iswide(unsigned int);
static void usage(void);
-
-static int opt_minus_w;
-static int opt_plus_w;
-static int removewide;
-static unsigned long threshold;
+static int parse_threshold(const char *str, unsigned long *threshold);
static int
-parse_threshold(const char *str)
+parse_threshold(const char *str, unsigned long *threshold)
{
int base;
char *end_ptr;
@@ -63,14 +59,14 @@ parse_threshold(const char *str)
base = 10;
errno = 0;
- threshold = strtoul(str, &end_ptr, base);
- if (errno != 0 || threshold == 0)
+ *threshold = strtoul(str, &end_ptr, base);
+ if (errno != 0 || *threshold == 0)
return 1;
return 0;
}
static void
-process_line(const char *line)
+process_line(const char *line, int removewide, unsigned long threshold)
{
if (strncmp(line, "ENCODING", 8) == 0) {
unsigned long enc;
@@ -120,6 +116,9 @@ int
main(int argc, char **argv)
{
int removewide;
+ unsigned long threshold;
+ int opt_minus_w;
+ int opt_plus_w;
char *line, *input_ptr;
size_t line_len, rest_len;
@@ -139,7 +138,7 @@ main(int argc, char **argv)
if (argc != 1 || (opt_plus_w && opt_minus_w))
usage();
- if (parse_threshold(*argv)) {
+ if (parse_threshold(*argv, &threshold)) {
fprintf(stderr, "Illegal threshold %s\n", *argv);
usage();
}
@@ -178,7 +177,7 @@ main(int argc, char **argv)
break;
}
}
- process_line(line);
+ process_line(line, removewide, threshold);
}
return EXIT_SUCCESS;