diff options
Diffstat (limited to 'gnulib-tests/getcwd-lgpl.c')
-rw-r--r-- | gnulib-tests/getcwd-lgpl.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/gnulib-tests/getcwd-lgpl.c b/gnulib-tests/getcwd-lgpl.c index 9f0e007..fca6bde 100644 --- a/gnulib-tests/getcwd-lgpl.c +++ b/gnulib-tests/getcwd-lgpl.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2011-2018 Free Software Foundation, Inc. +/* Copyright (C) 2011-2020 Free Software Foundation, Inc. This file is part of gnulib. This program is free software: you can redistribute it and/or modify @@ -115,10 +115,15 @@ rpl_getcwd (char *buf, size_t size) } else { - /* Trim to fit, if possible. */ - result = realloc (buf, strlen (buf) + 1); - if (!result) - result = buf; + /* Here result == buf. */ + /* Shrink result before returning it. */ + size_t actual_size = strlen (result) + 1; + if (actual_size < size) + { + char *shrinked_result = realloc (result, actual_size); + if (shrinked_result != NULL) + result = shrinked_result; + } } return result; } |