Mercurial > octave
changeset 26439:4d5bf84ae249 stable
lo-utils.cc: Fix static analyzer detected issues (bug #55347).
* lo-utils.cc (octave_fgets): Check validity of pointers before using and call
current_liboctave_error_handler to exit if necessary.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 04 Jan 2019 16:53:13 -0800 |
parents | c048a6ac0f79 |
children | dc68f987c9ba |
files | liboctave/util/lo-utils.cc |
diffstat | 1 files changed, 10 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/util/lo-utils.cc Fri Jan 04 16:23:59 2019 -0800 +++ b/liboctave/util/lo-utils.cc Fri Jan 04 16:53:13 2019 -0800 @@ -102,6 +102,9 @@ int max_size = grow_size; char *buf = static_cast<char *> (std::malloc (max_size)); + if (! buf) + (*current_liboctave_error_handler) ("octave_fgets: unable to malloc %d bytes", max_size); + char *bufptr = buf; int len = 0; @@ -116,7 +119,13 @@ int tmp = bufptr - buf + grow_size - 1; grow_size *= 2; max_size += grow_size; - buf = static_cast<char *> (std::realloc (buf, max_size)); + auto tmpbuf = static_cast<char *> (std::realloc (buf, max_size)); + if (! tmpbuf) + { + free (buf); + (*current_liboctave_error_handler) ("octave_fgets: unable to realloc %d bytes", max_size); + } + buf = tmpbuf; bufptr = buf + tmp; if (*(bufptr-1) == '\n')