[vlc-commits] strings: vlc_strfinput: use checked alloc
Francois Cartegnie
git at videolan.org
Wed Jul 20 16:25:02 CEST 2016
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Jul 19 21:02:54 2016 +0200| [b771b09a49190ac2fcd1d6cd607f30755ce210ea] | committer: Francois Cartegnie
strings: vlc_strfinput: use checked alloc
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b771b09a49190ac2fcd1d6cd607f30755ce210ea
---
src/text/strings.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/text/strings.c b/src/text/strings.c
index c5cd3fd..5ebf46c 100644
--- a/src/text/strings.c
+++ b/src/text/strings.c
@@ -526,7 +526,7 @@ static int write_meta(FILE *stream, input_item_t *item, vlc_meta_type_t type)
char *vlc_strfinput(input_thread_t *input, const char *s)
{
- char *str;
+ char *str = NULL;
size_t len;
#ifdef HAVE_OPEN_MEMSTREAM
FILE *stream = open_memstream(&str, &len);
@@ -812,15 +812,16 @@ char *vlc_strfinput(input_thread_t *input, const char *s)
return (fclose(stream) == 0) ? str : NULL;
#else
len = ftell(stream);
- if (len != (size_t)-1)
+ if (len != (size_t)-1 && len != SIZE_MAX)
{
rewind(stream);
- str = xmalloc(len + 1);
- fread(str, len, 1, stream);
- str[len] = '\0';
+ str = malloc(len + 1);
+ if(str)
+ {
+ fread(str, len, 1, stream);
+ str[len] = '\0';
+ }
}
- else
- str = NULL;
fclose(stream);
return str;
#endif
More information about the vlc-commits
mailing list