bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug in truncate


From: Eric Blake
Subject: bug in truncate
Date: Thu, 7 May 2009 20:41:47 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Cygwin recently improved its <ctype.h> to trigger gcc -Wall warnings on common 
abuses of ctype macros.  As a result, I now see this failure:

truncate.c: In function `main':
truncate.c:290: warning: subscript has type `char'
truncate.c:312: warning: subscript has type `char'

On platforms where char is signed, and in single-byte locales where 0xff is a 
space (yes, there are such locales), and where EOF is the traditional value of -
1, then isspace((char)0xff) and isspace((unsigned char)0xff) give different 
results.  OK to apply this patch?


From: Eric Blake <address@hidden>
Date: Thu, 7 May 2009 14:27:37 -0600
Subject: [PATCH] truncate: fix bug in use of isspace

* src/truncate.c (main): Pass unsigned characters to isspace.
* NEWS: Mention this.
---
 NEWS           |    4 ++++
 src/truncate.c |    6 +++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 6f2a401..31f1b1a 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ GNU coreutils NEWS                                    -*- 
outline -*-

 * Noteworthy changes in release ?.? (????-??-??) [?]

+** Bug fixes
+
+  truncate -s failed to skip all whitespace in the option argument in
+  some locales.

 * Noteworthy changes in release 7.4 (2009-05-07) [stable]

diff --git a/src/truncate.c b/src/truncate.c
index 06fa03a..f483f97 100644
--- a/src/truncate.c
+++ b/src/truncate.c
@@ -1,5 +1,5 @@
 /* truncate -- truncate or extend the length of files.
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-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
@@ -287,7 +287,7 @@ main (int argc, char **argv)

         case 's':
           /* skip any whitespace */
-          while (isspace (*optarg))
+          while (isspace (to_uchar (*optarg)))
             optarg++;
           switch (*optarg)
             {
@@ -309,7 +309,7 @@ main (int argc, char **argv)
               break;
             }
           /* skip any whitespace */
-          while (isspace (*optarg))
+          while (isspace (to_uchar (*optarg)))
             optarg++;
           if (*optarg == '+' || *optarg == '-')
             {
-- 
1.6.2.4






reply via email to

[Prev in Thread] Current Thread [Next in Thread]