mbrtoc16: Fix undefined behaviour.
[gnulib.git] / lib / unistdio / u-vasprintf.h
blobbc04a0f5051f7f4af8eb72329a668365ca828792
1 /* Formatted output to strings.
2 Copyright (C) 1999, 2002, 2006-2024 Free Software Foundation, Inc.
4 This file is free software.
5 It is dual-licensed under "the GNU LGPLv3+ or the GNU GPLv2+".
6 You can redistribute it and/or modify it under either
7 - the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation, either version 3, or (at your
9 option) any later version, or
10 - the terms of the GNU General Public License as published by the
11 Free Software Foundation; either version 2, or (at your option)
12 any later version, or
13 - the same dual license "the GNU LGPLv3+ or the GNU GPLv2+".
15 This file is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License and the GNU General Public License
19 for more details.
21 You should have received a copy of the GNU Lesser General Public
22 License and of the GNU General Public License along with this
23 program. If not, see <https://www.gnu.org/licenses/>. */
25 int
26 VASPRINTF (DCHAR_T **resultp, const FCHAR_T *format, va_list args)
28 size_t length;
29 DCHAR_T *result = VASNPRINTF (NULL, &length, format, args);
30 if (result == NULL)
31 return -1;
33 if (length > INT_MAX)
35 free (result);
36 errno = EOVERFLOW;
37 return -1;
40 *resultp = result;
41 /* Return the number of resulting units, excluding the trailing NUL. */
42 return length;