public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/49953] New: _toupper() and _tolower() macros in ctype.h are broken
@ 2011-08-03  5:13 jmichae3 at yahoo dot com
  2011-08-03  5:43 ` [Bug libstdc++/49953] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: jmichae3 at yahoo dot com @ 2011-08-03  5:13 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49953

           Summary: _toupper() and _tolower() macros in ctype.h are broken
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jmichae3@yahoo.com


not sure if I categorized this correctly.
in ctype.h I found
#define _tolower(_Char) ((_Char)-'A'+'a')
#define _toupper(_Char) ((_Char)-'a'+'A')

this code is broken when it is used in the situations where the character is
already in the desired case.  then you get garbage characters.
try it yourself.
example: _tolower('a') produces garbage.


#include <ctype.h>
#include <stdio.h>
int main(void) {
    printf("%c%c", _toupper('A'),_tolower('a')); 
    //result is !ü which is not proper
    return 0;
}

a proper bug fix would be

#define _tolower(_Char) ((_Char>='A'&&_Char<='Z')?_Char+('a'-'A'):_Char)
#define _toupper(_Char) ((_Char>='a'&&_Char<='z')?_Char-('a'-'A'):_Char)


//#include <ctype.h>
#include <stdio.h>
#define _tolower(_Char) ((_Char>='A'&&_Char<='Z')?_Char+('a'-'A'):_Char)
#define _toupper(_Char) ((_Char>='a'&&_Char<='z')?_Char-('a'-'A'):_Char)
int main(void) {
    printf("%c%c%c%c", _toupper('A'),_toupper('a'),
_tolower('A'),_tolower('a'));
    //result is AAaa
    return 0;
}


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libstdc++/49953] _toupper() and _tolower() macros in ctype.h are broken
  2011-08-03  5:13 [Bug libstdc++/49953] New: _toupper() and _tolower() macros in ctype.h are broken jmichae3 at yahoo dot com
@ 2011-08-03  5:43 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-08-03  5:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49953

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-08-03 05:42:28 UTC ---
_tolower and _toupper are internal macros to ctype.h and should not be used
directly.  Also GCC does not include a ctype.h rather it comes from the libc
you are using (most likely glibc or newlib).


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-03  5:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-03  5:13 [Bug libstdc++/49953] New: _toupper() and _tolower() macros in ctype.h are broken jmichae3 at yahoo dot com
2011-08-03  5:43 ` [Bug libstdc++/49953] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).