unsigned char portability casts

This commit is contained in:
christos 2012-03-21 14:19:15 +00:00
parent de7ac11be7
commit d9285aa434
2 changed files with 23 additions and 15 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfwprintf.c,v 1.28 2012/03/15 18:22:30 christos Exp $ */
/* $NetBSD: vfwprintf.c,v 1.29 2012/03/21 14:20:47 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -38,7 +38,7 @@
static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
__FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.27 2007/01/09 00:28:08 imp Exp $");
#else
__RCSID("$NetBSD: vfwprintf.c,v 1.28 2012/03/15 18:22:30 christos Exp $");
__RCSID("$NetBSD: vfwprintf.c,v 1.29 2012/03/21 14:20:47 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -290,8 +290,9 @@ __ultoa(u_long val, CHAR_T *endp, int base, int octzero, const char *xdigs,
* If (*grp == CHAR_MAX) then no more grouping
* should be performed.
*/
if (needgrp && ndig == *grp && *grp != CHAR_MAX
&& sval > 9) {
if (needgrp && ndig == *grp
&& (unsigned char)*grp != (unsigned char)CHAR_MAX
&& sval > 9) {
*--cp = thousep;
ndig = 0;
/*
@ -362,8 +363,10 @@ __ujtoa(uintmax_t val, CHAR_T *endp, int base, int octzero,
* If (*grp == CHAR_MAX) then no more grouping
* should be performed.
*/
if (needgrp && *grp != CHAR_MAX && ndig == *grp
&& sval > 9) {
if (needgrp
&& (unsigned char)*grp != (unsigned char)CHAR_MAX
&& ndig == *grp
&& sval > 9) {
*--cp = thousep;
ndig = 0;
/*
@ -1240,7 +1243,8 @@ fp_common:
/* space for thousands' grouping */
nseps = nrepeats = 0;
lead = expt;
while (*grouping != CHAR_MAX) {
while ((unsigned char)*grouping
!= (unsigned char)CHAR_MAX) {
if (lead <= *grouping)
break;
lead -= *grouping;

View File

@ -1,4 +1,4 @@
/* $NetBSD: strfmon.c,v 1.9 2012/03/13 21:13:48 christos Exp $ */
/* $NetBSD: strfmon.c,v 1.10 2012/03/21 14:19:15 christos Exp $ */
/*-
* Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
@ -32,7 +32,7 @@
#if 0
__FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $");
#else
__RCSID("$NetBSD: strfmon.c,v 1.9 2012/03/13 21:13:48 christos Exp $");
__RCSID("$NetBSD: strfmon.c,v 1.10 2012/03/21 14:19:15 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -63,6 +63,10 @@ __RCSID("$NetBSD: strfmon.c,v 1.9 2012/03/13 21:13:48 christos Exp $");
#define USE_INTL_CURRENCY 0x40 /* use international currency symbol */
#define IS_NEGATIVE 0x80 /* is argument value negative ? */
#ifndef NBCHAR_MAX
#define NBCHAR_MAX ((unsigned char)CHAR_MAX)
#endif
/* internal macros */
#define PRINT(CH) do { \
if (dst >= s + maxsize) \
@ -443,9 +447,9 @@ __setup_vars(int flags, char *cs_precedes, char *sep_by_space,
/* Set defult values for unspecified information. */
if (*cs_precedes != 0)
*cs_precedes = 1;
if (*sep_by_space == CHAR_MAX)
if ((unsigned char)*sep_by_space == NBCHAR_MAX)
*sep_by_space = 0;
if (*sign_posn == CHAR_MAX)
if ((unsigned char)*sign_posn == NBCHAR_MAX)
*sign_posn = 0;
}
@ -482,14 +486,14 @@ get_groups(int size, char *grouping) {
int chars = 0;
if (*grouping == CHAR_MAX || *grouping <= 0) /* no grouping ? */
if ((unsigned char)*grouping == NBCHAR_MAX || *grouping <= 0) /* no grouping ? */
return (0);
while (size > (int)*grouping) {
chars++;
size -= (int)*grouping++;
/* no more grouping ? */
if (*grouping == CHAR_MAX)
if ((unsigned char)*grouping == NBCHAR_MAX)
break;
/* rest grouping with same value ? */
if (*grouping == 0) {
@ -581,7 +585,7 @@ __format_grouped_double(double value, int *flags,
/* XXX: Why not use %' instead? */
if ((*flags & NEED_GROUPING) &&
thousands_sep != '\0' && /* XXX: need investigation */
*grouping != CHAR_MAX &&
(unsigned char)*grouping != NBCHAR_MAX &&
*grouping > 0) {
while (avalue_size > (int)*grouping) {
GRPCPY(*grouping);
@ -589,7 +593,7 @@ __format_grouped_double(double value, int *flags,
grouping++;
/* no more grouping ? */
if (*grouping == CHAR_MAX)
if ((unsigned char)*grouping == NBCHAR_MAX)
break;
/* rest grouping with same value ? */