Merge "Guard registers definitions for riscv64"
diff --git a/libc/include/inttypes.h b/libc/include/inttypes.h
index f8b7f7d..76aee38 100644
--- a/libc/include/inttypes.h
+++ b/libc/include/inttypes.h
@@ -85,6 +85,42 @@
#define PRIiPTR __PRI_PTR_prefix"i" /* intptr_t */
/* fprintf macros for unsigned integers */
+#define PRIb8 "b" /* int8_t */
+#define PRIb16 "b" /* int16_t */
+#define PRIb32 "b" /* int32_t */
+#define PRIb64 __PRI_64_prefix"b" /* int64_t */
+
+#define PRIbLEAST8 "b" /* int_least8_t */
+#define PRIbLEAST16 "b" /* int_least16_t */
+#define PRIbLEAST32 "b" /* int_least32_t */
+#define PRIbLEAST64 __PRI_64_prefix"b" /* int_least64_t */
+
+#define PRIbFAST8 "b" /* int_fast8_t */
+#define PRIbFAST16 __PRI_FAST_prefix"b" /* int_fast16_t */
+#define PRIbFAST32 __PRI_FAST_prefix"b" /* int_fast32_t */
+#define PRIbFAST64 __PRI_64_prefix"b" /* int_fast64_t */
+
+#define PRIbMAX "jb" /* intmax_t */
+#define PRIbPTR __PRI_PTR_prefix"b" /* intptr_t */
+
+#define PRIB8 "B" /* int8_t */
+#define PRIB16 "B" /* int16_t */
+#define PRIB32 "B" /* int32_t */
+#define PRIB64 __PRI_64_prefix"B" /* int64_t */
+
+#define PRIBLEAST8 "B" /* int_least8_t */
+#define PRIBLEAST16 "B" /* int_least16_t */
+#define PRIBLEAST32 "B" /* int_least32_t */
+#define PRIBLEAST64 __PRI_64_prefix"B" /* int_least64_t */
+
+#define PRIBFAST8 "B" /* int_fast8_t */
+#define PRIBFAST16 __PRI_FAST_prefix"B" /* int_fast16_t */
+#define PRIBFAST32 __PRI_FAST_prefix"B" /* int_fast32_t */
+#define PRIBFAST64 __PRI_64_prefix"B" /* int_fast64_t */
+
+#define PRIBMAX "jB" /* intmax_t */
+#define PRIBPTR __PRI_PTR_prefix"B" /* intptr_t */
+
#define PRIo8 "o" /* int8_t */
#define PRIo16 "o" /* int16_t */
#define PRIo32 "o" /* int32_t */
@@ -195,6 +231,42 @@
#define SCNiPTR __PRI_PTR_prefix"i" /* intptr_t */
/* fscanf macros for unsigned integers */
+#define SCNb8 "hhb" /* uint8_t */
+#define SCNb16 "hb" /* uint16_t */
+#define SCNb32 "b" /* uint32_t */
+#define SCNb64 __PRI_64_prefix"b" /* uint64_t */
+
+#define SCNbLEAST8 "hhb" /* uint_least8_t */
+#define SCNbLEAST16 "hb" /* uint_least16_t */
+#define SCNbLEAST32 "b" /* uint_least32_t */
+#define SCNbLEAST64 __PRI_64_prefix"b" /* uint_least64_t */
+
+#define SCNbFAST8 "hhb" /* uint_fast8_t */
+#define SCNbFAST16 __PRI_FAST_prefix"b" /* uint_fast16_t */
+#define SCNbFAST32 __PRI_FAST_prefix"b" /* uint_fast32_t */
+#define SCNbFAST64 __PRI_64_prefix"b" /* uint_fast64_t */
+
+#define SCNbMAX "jb" /* uintmax_t */
+#define SCNbPTR __PRI_PTR_prefix"b" /* uintptr_t */
+
+#define SCNB8 "hhB" /* uint8_t */
+#define SCNB16 "hB" /* uint16_t */
+#define SCNB32 "B" /* uint32_t */
+#define SCNB64 __PRI_64_prefix"B" /* uint64_t */
+
+#define SCNBLEAST8 "hhB" /* uint_least8_t */
+#define SCNBLEAST16 "hB" /* uint_least16_t */
+#define SCNBLEAST32 "B" /* uint_least32_t */
+#define SCNBLEAST64 __PRI_64_prefix"B" /* uint_least64_t */
+
+#define SCNBFAST8 "hhB" /* uint_fast8_t */
+#define SCNBFAST16 __PRI_FAST_prefix"B" /* uint_fast16_t */
+#define SCNBFAST32 __PRI_FAST_prefix"B" /* uint_fast32_t */
+#define SCNBFAST64 __PRI_64_prefix"B" /* uint_fast64_t */
+
+#define SCNBMAX "jB" /* uintmax_t */
+#define SCNBPTR __PRI_PTR_prefix"B" /* uintptr_t */
+
#define SCNo8 "hho" /* uint8_t */
#define SCNo16 "ho" /* uint16_t */
#define SCNo32 "o" /* uint32_t */
diff --git a/libc/tzcode/strptime.c b/libc/tzcode/strptime.c
index fe9e10f..d31a501 100644
--- a/libc/tzcode/strptime.c
+++ b/libc/tzcode/strptime.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: strptime.c,v 1.30 2019/05/12 12:49:52 schwarze Exp $ */
+/* $OpenBSD: strptime.c,v 1.31 2023/03/02 16:21:51 millert Exp $ */
/* $NetBSD: strptime.c,v 1.12 1998/01/20 21:39:40 mycroft Exp $ */
/*-
* Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc.
@@ -29,8 +29,10 @@
*/
#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
#include <locale.h>
-#include <stdint.h>
+#include <stdlib.h>
#include <string.h>
#include <time.h>
@@ -43,6 +45,8 @@
// Android: this code is not pointer-sign clean.
#pragma clang diagnostic ignored "-Wpointer-sign"
#pragma clang diagnostic ignored "-Wunused-function"
+// Android: clang thinks people don't know && has higher precedence than ||.
+#pragma clang diagnostic ignored "-Wlogical-op-parentheses"
#define _ctloc(x) (_CurrentTimeLocale->x)
@@ -78,8 +82,8 @@
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
-static int _conv_num64(const unsigned char **, int64_t *, int64_t, int64_t);
static int _conv_num(const unsigned char **, int *, int, int);
+static int epoch_to_tm(const unsigned char **, struct tm *);
static int leaps_thru_end_of(const int y);
static char *_strptime(const char *, const char *, struct tm *, int);
static const u_char *_find_string(const u_char *, int *, const char * const *,
@@ -351,27 +355,10 @@
if (!(_conv_num(&bp, &tm->tm_sec, 0, 60)))
return (NULL);
break;
- case 's': /* Seconds since epoch */
- {
- // Android change based on FreeBSD's implementation.
- int saved_errno = errno;
- errno = 0;
- const unsigned char* old_bp = bp;
- long n = strtol((const char*) bp, (char**) &bp, 10);
- errno = saved_errno;
- time_t t = n;
- if (bp == old_bp || errno == ERANGE ||
- ((long) t) != n) return NULL;
-
- if (localtime_r(&t, tm) == NULL) return NULL;
-
- //int64_t i64;
- //if (!(_conv_num64(&bp, &i64, 0, INT64_MAX)))
- // return (NULL);
- //if (!gmtime_r(&i64, tm))
- // return (NULL);
- fields = 0xffff; /* everything */
- }
+ case 's': /* Seconds since epoch. */
+ if (!(epoch_to_tm(&bp, tm)))
+ return (NULL);
+ fields = 0xffff; /* everything */
break;
case 'U': /* The week of year, beginning on sunday. */
case 'W': /* The week of year, beginning on monday. */
@@ -635,26 +622,27 @@
}
static int
-_conv_num64(const unsigned char **buf, int64_t *dest, int64_t llim, int64_t ulim)
+epoch_to_tm(const unsigned char **buf, struct tm *tm)
{
- int result = 0;
- int64_t rulim = ulim;
+ int saved_errno = errno;
+ int ret = 0;
+ time_t secs;
+ char *ep;
- if (**buf < '0' || **buf > '9')
- return (0);
-
- /* we use rulim to break out of the loop when we run out of digits */
- do {
- result *= 10;
- result += *(*buf)++ - '0';
- rulim /= 10;
- } while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9');
-
- if (result < llim || result > ulim)
- return (0);
-
- *dest = result;
- return (1);
+ errno = 0;
+ secs = strtoll(*buf, &ep, 10);
+ if (*buf == (unsigned char *)ep)
+ goto done;
+ if (secs < 0 ||
+ secs == LLONG_MAX && errno == ERANGE)
+ goto done;
+ if (localtime_r(&secs, tm) == NULL)
+ goto done;
+ ret = 1;
+done:
+ *buf = ep;
+ errno = saved_errno;
+ return (ret);
}
static const u_char *
diff --git a/libc/upstream-openbsd/lib/libc/gdtoa/gdtoaimp.h b/libc/upstream-openbsd/lib/libc/gdtoa/gdtoaimp.h
index 823f2a9..f853045 100644
--- a/libc/upstream-openbsd/lib/libc/gdtoa/gdtoaimp.h
+++ b/libc/upstream-openbsd/lib/libc/gdtoa/gdtoaimp.h
@@ -26,7 +26,7 @@
****************************************************************/
-/* This is a variation on dtoa.c that converts arbitary binary
+/* This is a variation on dtoa.c that converts arbitrary binary
floating-point formats to and from decimal notation. It uses
double-precision arithmetic internally, so there are still
various #ifdefs that adapt the calculations to the native
diff --git a/libc/upstream-openbsd/lib/libc/stdio/setvbuf.c b/libc/upstream-openbsd/lib/libc/stdio/setvbuf.c
index 9a08d13..74a1695 100644
--- a/libc/upstream-openbsd/lib/libc/stdio/setvbuf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/setvbuf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: setvbuf.c,v 1.14 2016/09/21 04:38:56 guenther Exp $ */
+/* $OpenBSD: setvbuf.c,v 1.15 2022/09/28 16:44:14 gnezdo Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,6 +31,7 @@
* SUCH DAMAGE.
*/
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include "local.h"
@@ -52,7 +53,7 @@
* when setting _IONBF.
*/
if (mode != _IONBF)
- if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0)
+ if ((mode != _IOFBF && mode != _IOLBF) || size > INT_MAX)
return (EOF);
/*
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/div.c b/libc/upstream-openbsd/lib/libc/stdlib/div.c
index beaa428..5e6164f 100644
--- a/libc/upstream-openbsd/lib/libc/stdlib/div.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/div.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: div.c,v 1.6 2015/09/13 08:31:47 guenther Exp $ */
+/* $OpenBSD: div.c,v 1.7 2022/12/27 17:10:06 jmc Exp $ */
/*
* Copyright (c) 1990 Regents of the University of California.
* All rights reserved.
@@ -46,7 +46,7 @@
* words, we should always truncate the quotient towards
* 0, never -infinity.
*
- * Machine division and remainer may work either way when
+ * Machine division and remainder may work either way when
* one or both of n or d is negative. If only one is
* negative and r.quot has been truncated towards -inf,
* r.rem will have the same sign as denom and the opposite
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/setenv.c b/libc/upstream-openbsd/lib/libc/stdlib/setenv.c
index 15c550b..fc8e5b6 100644
--- a/libc/upstream-openbsd/lib/libc/stdlib/setenv.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/setenv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: setenv.c,v 1.19 2016/09/21 04:38:56 guenther Exp $ */
+/* $OpenBSD: setenv.c,v 1.20 2022/08/08 22:40:03 millert Exp $ */
/*
* Copyright (c) 1987 Regents of the University of California.
* All rights reserved.
@@ -48,9 +48,10 @@
for (cp = str; *cp && *cp != '='; ++cp)
;
- if (*cp != '=') {
+ if (cp == str || *cp != '=') {
+ /* '=' is the first character of string or is missing. */
errno = EINVAL;
- return (-1); /* missing `=' in string */
+ return (-1);
}
if (__findenv(str, (int)(cp - str), &offset) != NULL) {
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index acc7ccd..a8db1b0 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -2975,9 +2975,6 @@
}
TEST(STDIO_TEST, snprintf_b) {
- // Our clang doesn't know about %b/%B yet.
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wformat-invalid-specifier"
char buf[BUFSIZ];
EXPECT_EQ(5, snprintf(buf, sizeof(buf), "<%b>", 5));
EXPECT_STREQ("<101>", buf);
@@ -2989,13 +2986,9 @@
EXPECT_STREQ("<0b10101010101010101010101010101010>", buf);
EXPECT_EQ(3, snprintf(buf, sizeof(buf), "<%#b>", 0));
EXPECT_STREQ("<0>", buf);
-#pragma clang diagnostic pop
}
TEST(STDIO_TEST, snprintf_B) {
- // Our clang doesn't know about %b/%B yet.
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wformat-invalid-specifier"
char buf[BUFSIZ];
EXPECT_EQ(5, snprintf(buf, sizeof(buf), "<%B>", 5));
EXPECT_STREQ("<101>", buf);
@@ -3007,13 +3000,9 @@
EXPECT_STREQ("<0B10101010101010101010101010101010>", buf);
EXPECT_EQ(3, snprintf(buf, sizeof(buf), "<%#B>", 0));
EXPECT_STREQ("<0>", buf);
-#pragma clang diagnostic pop
}
TEST(STDIO_TEST, swprintf_b) {
- // Our clang doesn't know about %b/%B yet.
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wformat-invalid-specifier"
wchar_t buf[BUFSIZ];
EXPECT_EQ(5, swprintf(buf, sizeof(buf), L"<%b>", 5));
EXPECT_EQ(std::wstring(L"<101>"), buf);
@@ -3025,13 +3014,9 @@
EXPECT_EQ(std::wstring(L"<0b10101010101010101010101010101010>"), buf);
EXPECT_EQ(3, swprintf(buf, sizeof(buf), L"<%#b>", 0));
EXPECT_EQ(std::wstring(L"<0>"), buf);
-#pragma clang diagnostic pop
}
TEST(STDIO_TEST, swprintf_B) {
- // Our clang doesn't know about %b/%B yet.
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wformat-invalid-specifier"
wchar_t buf[BUFSIZ];
EXPECT_EQ(5, swprintf(buf, sizeof(buf), L"<%B>", 5));
EXPECT_EQ(std::wstring(L"<101>"), buf);
@@ -3043,7 +3028,6 @@
EXPECT_EQ(std::wstring(L"<0B10101010101010101010101010101010>"), buf);
EXPECT_EQ(3, swprintf(buf, sizeof(buf), L"<%#B>", 0));
EXPECT_EQ(std::wstring(L"<0>"), buf);
-#pragma clang diagnostic pop
}
TEST(STDIO_TEST, scanf_i_decimal) {
@@ -3143,10 +3127,6 @@
}
TEST(STDIO_TEST, scanf_b) {
- // Our clang doesn't know about %b yet.
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wformat"
-#pragma clang diagnostic ignored "-Wformat-invalid-specifier"
int i;
char ch;
EXPECT_EQ(2, sscanf("<1012>", "<%b%c>", &i, &ch));
@@ -3159,14 +3139,9 @@
EXPECT_EQ(2, sscanf("-0b", "%i%c", &i, &ch));
EXPECT_EQ(0, i);
EXPECT_EQ('b', ch);
-#pragma clang diagnostic pop
}
TEST(STDIO_TEST, swscanf_b) {
- // Our clang doesn't know about %b yet.
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wformat"
-#pragma clang diagnostic ignored "-Wformat-invalid-specifier"
int i;
char ch;
EXPECT_EQ(2, swscanf(L"<1012>", L"<%b%c>", &i, &ch));
@@ -3179,5 +3154,4 @@
EXPECT_EQ(2, swscanf(L"-0b", L"%i%c", &i, &ch));
EXPECT_EQ(0, i);
EXPECT_EQ('b', ch);
-#pragma clang diagnostic pop
}