From 705fab49ebb511fcaacf1f7e106e4402154c0fbc Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 12 May 2009 12:12:15 +0300 Subject: [PATCH] Avoid undefined behavior * src/xheader.c (xheader_set_keyword_equal): Pass correct type to ctype macros. * src/transform.c (run_case_conv): Likewise. --- src/transform.c | 9 ++++----- src/xheader.c | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/transform.c b/src/transform.c index 2e0de31..03c06f6 100644 --- a/src/transform.c +++ b/src/transform.c @@ -430,21 +430,21 @@ run_case_conv (enum case_ctl_type case_ctl, char *ptr, size_t size) switch (case_ctl) { case ctl_upcase_next: - case_ctl_buffer[0] = toupper (case_ctl_buffer[0]); + case_ctl_buffer[0] = toupper ((unsigned char) case_ctl_buffer[0]); break; case ctl_locase_next: - case_ctl_buffer[0] = tolower (case_ctl_buffer[0]); + case_ctl_buffer[0] = tolower ((unsigned char) case_ctl_buffer[0]); break; case ctl_upcase: for (p = case_ctl_buffer; p < case_ctl_buffer + size; p++) - *p = toupper (*p); + *p = toupper ((unsigned char) *p); break; case ctl_locase: for (p = case_ctl_buffer; p < case_ctl_buffer + size; p++) - *p = tolower (*p); + *p = tolower ((unsigned char) *p); break; case ctl_stop: @@ -628,4 +628,3 @@ transform_name (char **pinput, int type) { return transform_name_fp (pinput, type, NULL, NULL); } - diff --git a/src/xheader.c b/src/xheader.c index 919ecd3..84ae08b 100644 --- a/src/xheader.c +++ b/src/xheader.c @@ -1,6 +1,6 @@ /* POSIX extended headers for tar. - Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009 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 the @@ -168,12 +168,12 @@ xheader_set_keyword_equal (char *kw, char *eq) global = false; } - while (p > kw && isspace (*p)) + while (p > kw && isspace ((unsigned char) *p)) p--; *p = 0; - for (p = eq + 1; *p && isspace (*p); p++) + for (p = eq + 1; *p && isspace ((unsigned char) *p); p++) ; if (strcmp (kw, "delete") == 0) -- 2.45.2