Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jean-Baptiste Kempf
libaacs
Commits
28af032c
Commit
28af032c
authored
Apr 28, 2015
by
npzacs
Browse files
str_printf(): return NULL if memory allocation fails
parent
6f920c49
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/util/strutl.c
View file @
28af032c
...
...
@@ -164,10 +164,17 @@ char *str_printf(const char *fmt, ...)
va_list
ap
;
int
len
;
int
size
=
100
;
char
*
tmp
,
*
str
;
char
*
tmp
,
*
str
=
NULL
;
str
=
malloc
(
size
);
while
(
1
)
{
tmp
=
realloc
(
str
,
size
);
if
(
tmp
==
NULL
)
{
X_FREE
(
str
);
return
NULL
;
}
str
=
tmp
;
/* Try to print in the allocated space. */
va_start
(
ap
,
fmt
);
len
=
vsnprintf
(
str
,
size
,
fmt
,
ap
);
...
...
@@ -183,12 +190,6 @@ char *str_printf(const char *fmt, ...)
size
=
len
+
1
;
/* precisely what is needed */
else
/* glibc 2.0 */
size
*=
2
;
/* twice the old size */
tmp
=
realloc
(
str
,
size
);
if
(
tmp
==
NULL
)
{
return
str
;
}
str
=
tmp
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment