From e15cbb4f48a9c5c0aae5acc88a7f56086fc9e51f Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Thu, 28 Apr 2011 00:39:17 -0700 Subject: bdftruncate: Properly support -w and +w Regression introduced by fb486bb1a5038912d064291b12c7aef5da3d8b63 Found-by: clang static analyzer Signed-off-by: Jeremy Huddleston --- bdftruncate.c | 21 ++++++++++----------- 1 file 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; -- cgit v1.2.1