mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-02 16:38:27 +02:00
[xmalloc] Hide valgrind warning.
Allocate the string to the next integer boundary to hide a valgrind warning.
This commit is contained in:
parent
1faf208093
commit
5efc88e910
1 changed files with 20 additions and 9 deletions
|
|
@ -89,10 +89,10 @@ xasprintf (char **strp, const char *fmt, ...)
|
|||
#define BUF_SIZE 1024
|
||||
va_list va;
|
||||
char buffer[BUF_SIZE];
|
||||
int ret;
|
||||
int ret, len;
|
||||
|
||||
va_start (va, fmt);
|
||||
ret = vsnprintf (buffer, sizeof(buffer), fmt, va);
|
||||
ret = vsnprintf (buffer, sizeof (buffer), fmt, va);
|
||||
va_end (va);
|
||||
|
||||
if (ret < 0) {
|
||||
|
|
@ -100,15 +100,26 @@ xasprintf (char **strp, const char *fmt, ...)
|
|||
exit (1);
|
||||
}
|
||||
|
||||
if (strlen (buffer) == sizeof(buffer) - 1) {
|
||||
CAIRO_BOILERPLATE_LOG ("Overflowed fixed buffer\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
*strp = strdup (buffer);
|
||||
if (!*strp) {
|
||||
len = (ret + sizeof (int)) & -sizeof (int);
|
||||
*strp = malloc (len);
|
||||
if (*strp == NULL) {
|
||||
CAIRO_BOILERPLATE_LOG ("Out of memory\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if ((unsigned) ret < sizeof (buffer)) {
|
||||
memcpy (*strp, buffer, ret);
|
||||
} else {
|
||||
va_start (va, fmt);
|
||||
ret = vsnprintf (*strp, len, fmt, va);
|
||||
va_end (va);
|
||||
|
||||
if (ret >= len) {
|
||||
free (*strp);
|
||||
CAIRO_BOILERPLATE_LOG ("Overflowed dynamic buffer\n");
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
memset (*strp + ret, 0, len-ret);
|
||||
#endif /* !HAVE_VASNPRINTF */
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue