1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

- Modified the locale-aware isalnum(), isalpha(), iscntrl(),

isdigit(), isgraph(), islower(), isprint(), ispunct(), isspace(),
  isupper(), isxdigit(), tolower() and toupper() functions
  to clamp the input parameter to the "unsigned char" range before
  it is submitted to the respective locale.library function. This
  should be in sync with what the specs demand, which state that
  if the input parameter is neither EOF nor in the range of an
  "unsigned char" variable, then the results are undefined.

- ungetc() now returns the input character, clamped to an unsigned
  char value, upon success. Previously, if the input parameter was
  negative and not EOF, the result was identical to the input, which
  could have had negative side-effects.


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14958 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2005-05-29 09:56:09 +00:00
parent fb4dae84aa
commit 2ced1d3293
17 changed files with 125 additions and 35 deletions

View File

@ -31,6 +31,20 @@
- Changed the definition of the D_S() macro to cast the pointer
address to an unsigned 32 bit integer.
- Modified the locale-aware isalnum(), isalpha(), iscntrl(),
isdigit(), isgraph(), islower(), isprint(), ispunct(), isspace(),
isupper(), isxdigit(), tolower() and toupper() functions
to clamp the input parameter to the "unsigned char" range before
it is submitted to the respective locale.library function. This
should be in sync with what the specs demand, which state that
if the input parameter is neither EOF nor in the range of an
"unsigned char" variable, then the results are undefined.
- ungetc() now returns the input character, clamped to an unsigned
char value, upon success. Previously, if the input parameter was
negative and not EOF, the result was identical to the input, which
could have had negative side-effects.
c.lib 1.192 (12.5.2005)

View File

@ -1,5 +1,5 @@
/*
* $Id: ctype_headers.h,v 1.4 2005-03-30 19:37:26 obarthel Exp $
* $Id: ctype_headers.h,v 1.5 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -60,6 +60,7 @@
#include <locale.h>
#include <assert.h>
#include <limits.h>
#include <ctype.h>
/****************************************************************************/

View File

@ -1,5 +1,5 @@
/*
* $Id: ctype_isalnum.c,v 1.3 2005-02-27 21:58:21 obarthel Exp $
* $Id: ctype_isalnum.c,v 1.4 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -55,7 +55,13 @@ isalnum(int c)
{
assert( LocaleBase != NULL );
result = IsAlNum(__locale_table[LC_CTYPE],(ULONG)c);
/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if(c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = IsAlNum(__locale_table[LC_CTYPE],(ULONG)(c & 255));
else
result = FALSE;
}
else
{

View File

@ -1,5 +1,5 @@
/*
* $Id: ctype_isalpha.c,v 1.3 2005-02-27 21:58:21 obarthel Exp $
* $Id: ctype_isalpha.c,v 1.4 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -53,7 +53,13 @@ isalpha(int c)
{
assert( LocaleBase != NULL );
result = IsAlpha(__locale_table[LC_CTYPE],(ULONG)c);
/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if(c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = IsAlpha(__locale_table[LC_CTYPE],(ULONG)(c & 255));
else
result = FALSE;
}
else
{

View File

@ -1,5 +1,5 @@
/*
* $Id: ctype_iscntrl.c,v 1.3 2005-02-27 21:58:21 obarthel Exp $
* $Id: ctype_iscntrl.c,v 1.4 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -53,7 +53,13 @@ iscntrl(int c)
{
assert( LocaleBase != NULL );
result = IsCntrl(__locale_table[LC_CTYPE],(ULONG)c);
/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if(c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = IsCntrl(__locale_table[LC_CTYPE],(ULONG)(c & 255));
else
result = FALSE;
}
else
{

View File

@ -1,5 +1,5 @@
/*
* $Id: ctype_isdigit.c,v 1.3 2005-02-27 21:58:21 obarthel Exp $
* $Id: ctype_isdigit.c,v 1.4 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -53,7 +53,13 @@ isdigit(int c)
{
assert( LocaleBase != NULL );
result = IsDigit(__locale_table[LC_CTYPE],(ULONG)c);
/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if(c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = IsDigit(__locale_table[LC_CTYPE],(ULONG)(c & 255));
else
result = FALSE;
}
else
{

View File

@ -1,5 +1,5 @@
/*
* $Id: ctype_isgraph.c,v 1.3 2005-02-27 21:58:21 obarthel Exp $
* $Id: ctype_isgraph.c,v 1.4 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -53,7 +53,13 @@ isgraph(int c)
{
assert( LocaleBase != NULL );
result = IsGraph(__locale_table[LC_CTYPE],(ULONG)c);
/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if(c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = IsGraph(__locale_table[LC_CTYPE],(ULONG)(c & 255));
else
result = FALSE;
}
else
{

View File

@ -1,5 +1,5 @@
/*
* $Id: ctype_islower.c,v 1.3 2005-02-27 21:58:21 obarthel Exp $
* $Id: ctype_islower.c,v 1.4 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -53,7 +53,13 @@ islower(int c)
{
assert( LocaleBase != NULL );
result = IsLower(__locale_table[LC_CTYPE],(ULONG)c);
/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if(c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = IsLower(__locale_table[LC_CTYPE],(ULONG)(c & 255));
else
result = FALSE;
}
else
{

View File

@ -1,5 +1,5 @@
/*
* $Id: ctype_isprint.c,v 1.3 2005-02-27 21:58:21 obarthel Exp $
* $Id: ctype_isprint.c,v 1.4 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -53,7 +53,13 @@ isprint(int c)
{
assert( LocaleBase != NULL );
result = IsPrint(__locale_table[LC_CTYPE],(ULONG)c);
/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if(c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = IsPrint(__locale_table[LC_CTYPE],(ULONG)(c & 255));
else
result = FALSE;
}
else
{

View File

@ -1,5 +1,5 @@
/*
* $Id: ctype_ispunct.c,v 1.3 2005-02-27 21:58:21 obarthel Exp $
* $Id: ctype_ispunct.c,v 1.4 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -53,7 +53,13 @@ ispunct(int c)
{
assert( LocaleBase != NULL );
result = IsPunct(__locale_table[LC_CTYPE],(ULONG)c);
/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if(c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = IsPunct(__locale_table[LC_CTYPE],(ULONG)(c & 255));
else
result = FALSE;
}
else
{

View File

@ -1,5 +1,5 @@
/*
* $Id: ctype_isspace.c,v 1.3 2005-02-27 21:58:21 obarthel Exp $
* $Id: ctype_isspace.c,v 1.4 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -53,7 +53,13 @@ isspace(int c)
{
assert( LocaleBase != NULL );
result = IsSpace(__locale_table[LC_CTYPE],(ULONG)c);
/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if(c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = IsSpace(__locale_table[LC_CTYPE],(ULONG)(c & 255));
else
result = FALSE;
}
else
{

View File

@ -1,5 +1,5 @@
/*
* $Id: ctype_isupper.c,v 1.3 2005-02-27 21:58:21 obarthel Exp $
* $Id: ctype_isupper.c,v 1.4 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -53,7 +53,13 @@ isupper(int c)
{
assert( LocaleBase != NULL );
result = IsUpper(__locale_table[LC_CTYPE],(ULONG)c);
/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if(c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = IsUpper(__locale_table[LC_CTYPE],(ULONG)(c & 255));
else
result = FALSE;
}
else
{

View File

@ -1,5 +1,5 @@
/*
* $Id: ctype_isxdigit.c,v 1.3 2005-02-27 21:58:21 obarthel Exp $
* $Id: ctype_isxdigit.c,v 1.4 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -53,7 +53,13 @@ isxdigit(int c)
{
assert( LocaleBase != NULL );
result = IsXDigit(__locale_table[LC_CTYPE],(ULONG)c);
/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if(c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = IsXDigit(__locale_table[LC_CTYPE],(ULONG)(c & 255));
else
result = FALSE;
}
else
{

View File

@ -1,5 +1,5 @@
/*
* $Id: ctype_tolower.c,v 1.3 2005-02-27 21:58:21 obarthel Exp $
* $Id: ctype_tolower.c,v 1.4 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -49,7 +49,13 @@ tolower(int c)
{
assert( LocaleBase != NULL );
result = ConvToLower(__locale_table[LC_CTYPE],(ULONG)c);
/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if(c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = ConvToLower(__locale_table[LC_CTYPE],(ULONG)(c & 255));
else
result = c;
}
else
{

View File

@ -1,5 +1,5 @@
/*
* $Id: ctype_toupper.c,v 1.3 2005-02-27 21:58:21 obarthel Exp $
* $Id: ctype_toupper.c,v 1.4 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -49,7 +49,13 @@ toupper(int c)
{
assert( LocaleBase != NULL );
result = ConvToUpper(__locale_table[LC_CTYPE],(ULONG)c);
/* The parameter must be either EOF or in the range of an
'unsigned char'. If it's not, then the behaviour is
undefined. */
if(c != EOF && ((0 <= c && c <= UCHAR_MAX) || ((c + 256) <= UCHAR_MAX)))
result = ConvToUpper(__locale_table[LC_CTYPE],(ULONG)(c & 255));
else
result = c;
}
else
{

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fputc.c,v 1.6 2005-04-24 08:46:37 obarthel Exp $
* $Id: stdio_fputc.c,v 1.7 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -128,7 +128,7 @@ __fputc(int c,FILE *stream,int buffer_mode)
/* Clip everything but the least significant eight bits. This
also takes care of the sign. Thus, a -1 (== EOF) always comes
out as 255. */
result = (c & 0xff);
result = (c & 255);
out:

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_ungetc.c,v 1.5 2005-02-27 18:09:11 obarthel Exp $
* $Id: stdio_ungetc.c,v 1.6 2005-05-29 09:56:09 obarthel Exp $
*
* :ts=4
*
@ -107,10 +107,6 @@ ungetc(int c,FILE *stream)
goto out;
}
/* The following should never happen. */
if(c < 0)
D(("warning -- pushback of negative number %ld!",c));
/* Get rid of the write buffer, if it's still around. */
if(__iob_write_buffer_is_valid(file) > 0 && __flush_iob_write_buffer(file) < 0)
{
@ -138,7 +134,8 @@ ungetc(int c,FILE *stream)
/* Replace the character just read. */
file->iob_Buffer[--file->iob_BufferPosition] = c;
result = c;
/* Clamp the result to an unsigned 8 bit value. */
result = (c & 255);
out: