|
219 | 219 | /* TCHAR_T is char. */ |
220 | 220 | /* Use snprintf if it exists under the name 'snprintf' or '_snprintf'. |
221 | 221 | But don't use it if it has problems. For example, |
222 | | - Solaris, QNX and z/OS sprintf fail if size == INT_MAX + 1u, |
223 | | - BeOS produces no output if 0x3000000 <= size, |
224 | | - and Linux libc5 with size = 1 writes without bounds, like sprintf. |
| 222 | + Solaris, QNX and z/OS snprintf fail if size == INT_MAX + 1u, |
| 223 | + BeOS snprintf produces no output if size >= 0x3000000, |
| 224 | + and Linux libc5 with size == 1 writes without bounds, like sprintf. |
225 | 225 | BSD snprintf, which fails if size == INT_MAX + 2u, is OK for us. |
226 | 226 | Use snprintf only on known-safe platforms: |
227 | | - glibc 2, Android, musl, the BSDs, macOS, Microsoft UCRT. */ |
| 227 | + glibc 2, musl libc, macOS, FreeBSD, NetBSD, OpenBSD, Android, |
| 228 | + Microsoft UCRT. */ |
228 | 229 | # if ((HAVE_SNPRINTF || HAVE_DECL__SNPRINTF) \ |
229 | | - && (2 <= __GLIBC__ || __ANDROID__ || MUSL_LIBC \ |
230 | | - || __FreeBSD__ || __DragonFly__ || __NetBSD__ || __OpenBSD__ \ |
231 | | - || (__APPLE__ && __MACH__) || _UCRT)) |
| 230 | + && (2 <= __GLIBC__ || MUSL_LIBC \ |
| 231 | + || (defined __APPLE__ && defined __MACH__) \ |
| 232 | + || (defined __FreeBSD__ || defined __DragonFly__) \ |
| 233 | + || defined __NetBSD__ || defined __OpenBSD__ \ |
| 234 | + || defined __ANDROID__ || defined _UCRT)) |
232 | 235 | # define USE_SNPRINTF 1 |
233 | 236 | # else |
234 | 237 | # define USE_SNPRINTF 0 |
@@ -6868,17 +6871,16 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, |
6868 | 6871 |
|
6869 | 6872 | /* Keep size (in bytes) in ptrdiff_t and size_t range. |
6870 | 6873 | Also, generate at most INT_MAX + 1 characters |
6871 | | - counting the trailing null, as that is the |
| 6874 | + counting the trailing NUL, as that is the |
6872 | 6875 | maximum the API allows. */ |
6873 | | - size_t |
6874 | | - bytes_max = MIN (PTRDIFF_MAX, SIZE_MAX), |
6875 | | - tchars_max = bytes_max / sizeof (TCHAR_T), |
6876 | | - API_max = MIN (tchars_max - 1, INT_MAX), |
6877 | | - maxlen_max = (API_max + 1 |
6878 | | - - (API_max + 1) % TCHARS_PER_DCHAR), |
6879 | | - maxlen = (MIN (allocated - length, |
6880 | | - maxlen_max / TCHARS_PER_DCHAR) |
6881 | | - * TCHARS_PER_DCHAR); |
| 6876 | + size_t bytes_max = MIN (PTRDIFF_MAX, SIZE_MAX); |
| 6877 | + size_t tchars_max = bytes_max / sizeof (TCHAR_T); |
| 6878 | + size_t API_max = MIN (tchars_max - 1, INT_MAX); |
| 6879 | + size_t maxlen_max = |
| 6880 | + (API_max + 1) - (API_max + 1) % TCHARS_PER_DCHAR; |
| 6881 | + size_t maxlen = |
| 6882 | + MIN (allocated - length, maxlen_max / TCHARS_PER_DCHAR) |
| 6883 | + * TCHARS_PER_DCHAR; |
6882 | 6884 | # define SNPRINTF_BUF(arg) \ |
6883 | 6885 | switch (prefix_count) \ |
6884 | 6886 | { \ |
|
0 commit comments