Browse Source

Revert commit by davidm to printf.c that initialized conv_num
needlessly. To do so increases the generated code size with bcc.
Eliminate duplicate define warnings in wstring.c.
Fix potentially broken preprocessor comparisons. The preprocessor
converts integers to maximal signed type, so inequality comparisons
involving UINTMAX_MAX, ULLONG_MAX, and (if no long long) ULONG_MAX
were potentially broken.

Manuel Novoa III 22 years ago
parent
commit
666e8f922f

+ 3 - 2
libc/misc/time/time.c

@@ -449,7 +449,8 @@ static int tm_isdst(register const struct tm *__restrict ptm)
 {
 	register rule_struct *r = _time_tzinfo;
 	long sec;
-	int i, isdst, isleap, day, day0, monlen, mday, oday;
+	int i, isdst, isleap, day, day0, monlen, mday;
+	int oday;					/* Note: oday can be uninitialized. */
 
 	isdst = 0;
 	if (r[1].tzname[0] != 0) {
@@ -1681,7 +1682,7 @@ struct tm *_time_t2tm(const time_t *__restrict timer,
 {
 	register int *p;
 	time_t t1, t, v;
-	int wday;
+	int wday;					/* Note: wday can be uninitialized. */
 
 	{
 		register const uint16_t *vp;

+ 1 - 1
libc/misc/wchar/wchar.c

@@ -85,7 +85,7 @@
 #undef L__wchar_wcsntoutf8s
 #endif
 
-#if WCHAR_MAX > 0xffffU
+#if WCHAR_MAX > 0xffffUL
 #define UTF_8_MAX_LEN 6
 #else
 #define UTF_8_MAX_LEN 3

+ 4 - 4
libc/stdio/printf.c

@@ -764,7 +764,7 @@ extern int _ppfs_parsespec(ppfs_t *ppfs)
 	int n;
 	int argtype[MAX_ARGS_PER_SPEC+2];
 	int argnumber[3];			/* width, precision, 1st data arg */
-	unsigned int conv_num = 0;
+	unsigned int conv_num;		/* This does not need to be initialized. */
 	static const char spec_flags[] = SPEC_FLAGS;
 	static const char spec_chars[] = SPEC_CHARS;/* TODO: b? */
 	static const char spec_ranges[] = SPEC_RANGES;
@@ -1723,14 +1723,14 @@ int sprintf(char *__restrict buf, const char * __restrict format, ...)
  */
 #define DIGITS_PER_BLOCK     9
 
-#if UINT_MAX >= 4294967295UL
+#if INT_MAX >= 2147483647L
 #define DIGIT_BLOCK_TYPE     int
 #define DB_FMT               "%.*d"
-#elif LONG_MAX >= 4294967295UL
+#elif LONG_MAX >= 2147483647L
 #define DIGIT_BLOCK_TYPE     long
 #define DB_FMT               "%.*ld"
 #else
-#error need at least 32 bit longs
+#warning need at least 32 bit longs
 #endif
 
 /* Maximum number of calls to fnprintf to output double. */

+ 3 - 3
libc/stdio/stdio.c

@@ -95,7 +95,7 @@
 
 #ifndef __STDIO_THREADSAFE
 
-#ifdef __BCC__
+#if defined(__BCC__) && 0
 #define UNLOCKED_STREAM(RETURNTYPE,NAME,PARAMS,ARGS,STREAM) \
 asm(".text\nexport _" "NAME" "_unlocked\n_" "NAME" "_unlocked = _" "NAME"); \
 RETURNTYPE NAME PARAMS
@@ -108,7 +108,7 @@ RETURNTYPE NAME PARAMS
 #define UNLOCKED(RETURNTYPE,NAME,PARAMS,ARGS) \
 	UNLOCKED_STREAM(RETURNTYPE,NAME,PARAMS,ARGS,stream)
 
-#ifdef __BCC__
+#if defined(__BCC__) && 0
 #define UNLOCKED_VOID_RETURN(NAME,PARAMS,ARGS) \
 asm(".text\nexport _" "NAME" "_unlocked\n_" "NAME" "_unlocked = _" "NAME"); \
 void NAME PARAMS
@@ -3274,7 +3274,7 @@ void _stdio_fdout(int fd, ...)
 
 /* Avoid using long long / and % operations to cut down dependencies on
  * libgcc.a.  Definitely helps on i386 at least. */
-#if (UINTMAX_MAX > UINT_MAX) && ((UINTMAX_MAX/UINT_MAX) - 2 <= UINT_MAX)
+#if (INTMAX_MAX > INT_MAX) && (((INTMAX_MAX/INT_MAX)/2) - 2 <= INT_MAX)
 #define INTERNAL_DIV_MOD
 #endif
 

+ 15 - 15
libc/stdlib/stdlib.c

@@ -84,14 +84,14 @@ double atof(const char *nptr)
 /**********************************************************************/
 #ifdef L_abs
 
-#if UINT_MAX < ULONG_MAX
+#if INT_MAX < LONG_MAX
 
 int abs(int j)
 {
 	return (j >= 0) ? j : -j;
 }
 
-#endif /* UINT_MAX < ULONG_MAX */
+#endif /* INT_MAX < LONG_MAX */
 
 #endif
 /**********************************************************************/
@@ -118,7 +118,7 @@ long int labs(long int j)
 /**********************************************************************/
 #ifdef L_llabs
 
-#if defined(ULLONG_MAX) && (ULLONG_MAX > ULONG_MAX)
+#if defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX)
 
 #if (ULLONG_MAX == UINTMAX_MAX)
 strong_alias(llabs,imaxabs)
@@ -129,20 +129,20 @@ long long int llabs(long long int j)
 	return (j >= 0) ? j : -j;
 }
 
-#endif /* defined(ULLONG_MAX) && (ULLONG_MAX > ULONG_MAX) */
+#endif /* defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) */
 
 #endif
 /**********************************************************************/
 #ifdef L_atoi
 
-#if UINT_MAX < ULONG_MAX 
+#if INT_MAX < LONG_MAX 
 
 int atoi(const char *nptr)
 {
 	return (int) strtol(nptr, (char **) NULL, 10);
 }
 
-#endif /* UINT_MAX < ULONG_MAX  */
+#endif /* INT_MAX < LONG_MAX  */
 
 #endif
 /**********************************************************************/
@@ -165,14 +165,14 @@ long atol(const char *nptr)
 /**********************************************************************/
 #ifdef L_atoll
 
-#if defined(ULLONG_MAX) && (ULLONG_MAX > ULONG_MAX)
+#if defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX)
 
 long long atoll(const char *nptr)
 {
 	return strtoll(nptr, (char **) NULL, 10);
 }
 
-#endif /* defined(ULLONG_MAX) && (ULLONG_MAX > ULONG_MAX) */
+#endif /* defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) */
 
 #endif
 /**********************************************************************/
@@ -195,7 +195,7 @@ long strtol(const char * __restrict str, char ** __restrict endptr, int base)
 /**********************************************************************/
 #ifdef L_strtoll
 
-#if defined(ULLONG_MAX) && (ULLONG_MAX > ULONG_MAX)
+#if defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX)
 
 #if (ULLONG_MAX == UINTMAX_MAX)
 strong_alias(strtoll,strtoimax)
@@ -207,7 +207,7 @@ long long strtoll(const char * __restrict str,
     return (long long) _stdlib_strto_ll(str, endptr, base, 1);
 }
 
-#endif /* defined(ULLONG_MAX) && (ULLONG_MAX > ULONG_MAX) */
+#endif /* defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) */
 
 #endif
 /**********************************************************************/
@@ -231,7 +231,7 @@ unsigned long strtoul(const char * __restrict str,
 /**********************************************************************/
 #ifdef L_strtoull
 
-#if defined(ULLONG_MAX) && (ULLONG_MAX > ULONG_MAX)
+#if defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX)
 
 #if (ULLONG_MAX == UINTMAX_MAX)
 strong_alias(strtoull,strtoumax)
@@ -243,7 +243,7 @@ unsigned long long strtoull(const char * __restrict str,
     return _stdlib_strto_ll(str, endptr, base, 0);
 }
 
-#endif /* defined(ULLONG_MAX) && (ULLONG_MAX > ULONG_MAX) */
+#endif /* defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) */
 
 #endif
 /**********************************************************************/
@@ -366,7 +366,7 @@ unsigned long _stdlib_strto_l(register const char * __restrict str,
 /**********************************************************************/
 #ifdef L__stdlib_strto_ll
 
-#if defined(ULLONG_MAX) && (ULLONG_MAX > ULONG_MAX)
+#if defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX)
 
 /* This is the main work fuction which handles both strtoll (sflag = 1) and
  * strtoull (sflag = 0). */
@@ -473,7 +473,7 @@ unsigned long long _stdlib_strto_ll(register const char * __restrict str,
 	return negative ? (unsigned long long)(-((long long)number)) : number;
 }
 
-#endif /* defined(ULLONG_MAX) && (ULLONG_MAX > ULONG_MAX) */
+#endif /* defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) */
 
 #endif
 /**********************************************************************/
@@ -632,7 +632,7 @@ void ssort (void  *base,
 
 /* TODO: clean up the following... */
 
-#if WCHAR_MAX > 0xffffU
+#if WCHAR_MAX > 0xffffUL
 #define UTF_8_MAX_LEN 6
 #else
 #define UTF_8_MAX_LEN 3

+ 6 - 0
libc/string/wstring.c

@@ -876,6 +876,9 @@ Wchar *Wstrstr(const Wchar *s1, const Wchar *s2)
 
 #endif
 /**********************************************************************/
+#undef Wstrspn
+#undef Wstrpbrk
+
 #ifdef L_wcstok
 #define L_strtok_r
 #define Wstrtok_r wcstok
@@ -1160,6 +1163,9 @@ void *memccpy(void * __restrict s1, const void * __restrict s2, int c, size_t n)
 
 #endif
 /**********************************************************************/
+#undef Wstrlen
+#undef Wstrcpy
+
 #ifdef L_wcsdup
 #define L_strdup
 #define Wstrdup wcsdup

+ 9 - 9
libc/sysdeps/linux/common/bits/uClibc_stdio.h

@@ -427,35 +427,35 @@ extern void __stdio_validate_FILE(FILE *stream);
 #include <limits.h>
 #include <stdint.h>
 
-#if UINTMAX_MAX <= 4294967295UL
+#if INTMAX_MAX <= 2147483647L
 #define __UIM_BUFLEN			12 /* 10 digits + 1 nul + 1 sign */
-#elif UINTMAX_MAX <= 18446744073709551615ULL
+#elif INTMAX_MAX <= 9223372036854775807LL
 #define __UIM_BUFLEN			22 /* 20 digits + 1 nul + 1 sign */
 #else
 #error unknown number of digits for intmax_t!
 #endif
 
-#ifdef ULLONG_MAX				/* --------------- */
-#if ULLONG_MAX <= 4294967295UL
+#ifdef LLONG_MAX				/* --------------- */
+#if LLONG_MAX <= 2147483647L
 #define __UIM_BUFLEN_LLONG		12 /* 10 digits + 1 nul + 1 sign */
-#elif ULLONG_MAX <= 18446744073709551615ULL
+#elif LLONG_MAX <= 9223372036854775807LL
 #define __UIM_BUFLEN_LLONG		22 /* 20 digits + 1 nul + 1 sign */
 #else
 #error unknown number of digits for long long!
 #endif
 #endif /* ULLONG_MAX ----------------------------- */
 
-#if ULONG_MAX <= 4294967295UL
+#if LONG_MAX <= 2147483647L
 #define __UIM_BUFLEN_LONG		12 /* 10 digits + 1 nul + 1 sign */
-#elif ULONG_MAX <= 18446744073709551615ULL
+#elif LONG_MAX <= 9223372036854775807LL
 #define __UIM_BUFLEN_LONG		22 /* 20 digits + 1 nul + 1 sign */
 #else
 #error unknown number of digits for long!
 #endif
 
-#if UINT_MAX <= 65536U
+#if INT_MAX <= 32767
 #define __UIM_BUFLEN_INT		7 /* 10 digits + 1 nul + 1 sign */
-#elif UINT_MAX <= 4294967295UL
+#elif INT_MAX <= 2147483647L
 #define __UIM_BUFLEN_INT		12 /* 10 digits + 1 nul + 1 sign */
 #else
 #error unknown number of digits for int!