several bug fixes after test-suite

This commit is contained in:
eck 1990-03-28 16:37:18 +00:00
parent 0bb4c0167c
commit c8c4c6e7a9
5 changed files with 19 additions and 18 deletions

View file

@ -501,6 +501,7 @@ _str_ext_cvt(char *s, char **ss, struct EXTEND *e)
if (c == 'E' || c == 'e') {
int exp1 = 0;
int sign = 1;
int exp_overflow = 0;
switch(*s) {
case '-':
@ -515,13 +516,16 @@ _str_ext_cvt(char *s, char **ss, struct EXTEND *e)
exp1 = 10 * exp1 + (c - '0');
if ((tmp = sign * exp1 + exp) > MAX_EXP ||
tmp < -MAX_EXP) {
errno = ERANGE;
exp_overflow = 1;
}
} while (c = *++s, isdigit(c));
if (ss) *ss = s;
}
exp += sign * exp1;
if (errno == ERANGE) exp = sign * MAX_EXP;
if (exp_overflow) {
exp = sign * MAX_EXP;
if (e->m1 != 0 || e->m2 != 0) errno = ERANGE;
}
}
if (e->m1 == 0 && e->m2 == 0) return;
e->exp = 63;

View file

@ -11,7 +11,6 @@ int
mbtowc(wchar_t *pwc, register const char *s, size_t n)
{
if (s == (const char *)NULL) return 0;
if (*s == '\0') return 0;
if (n <= 0) return 0;
if (pwc) *pwc = *s;
return (*s != 0);

View file

@ -74,14 +74,13 @@ string2long(register const char *nptr, char ** const endptr,
else *endptr = (char *)nptr;
}
/* We can't represent a negative unsigned long, nor a long that
* is smaller than LONG_MIN or larger than LONG_MAX.
*/
if (!ovfl) {
if (!is_signed)
if (sign < 0 && val != 0)
ovfl++;
else if (((sign < 0 && val > -LONG_MIN)
/* Overflow is only possible when converting a signed long.
* val is unsigned long, so -LONG_MIN is converted to
* unsigned long.
*/
if (is_signed
&& ( (sign < 0 && val > -LONG_MIN)
|| (sign > 0 && val > LONG_MAX)))
ovfl++;
}
@ -93,6 +92,5 @@ string2long(register const char *nptr, char ** const endptr,
else return LONG_MAX;
else return ULONG_MAX;
}
if (is_signed) return (unsigned long) sign * val;
else return val;
return (unsigned long) sign * val;
}

View file

@ -14,8 +14,8 @@ wcstombs(register char *s, register const wchar_t *pwcs, size_t n)
register int i = n;
while (--i >= 0) {
if (!(*s++ = *pwcs))
return n - i - 1;
if (!(*s++ = *pwcs++))
break;
}
return n - i;
return n - i - 1;
}

View file

@ -13,5 +13,5 @@ wctomb(char *s, wchar_t wchar)
if (!s) return 0; /* no state dependent codings */
*s = wchar;
return (wchar != 0);
return (*s != '\0');
}