summaryrefslogtreecommitdiff
path: root/gnulib-tests/getcwd-lgpl.c
diff options
context:
space:
mode:
authorClint Adams <clint@debian.org>2021-08-31 08:53:23 -0400
committerClint Adams <clint@debian.org>2021-08-31 08:53:23 -0400
commitc50de48f2ed0b9476c3389fd07a85a5e8be798e2 (patch)
tree80f254d789336981f5ea660741739f70d46589d5 /gnulib-tests/getcwd-lgpl.c
parent637a2e292881341dde845545517b0ed3d3ccfc94 (diff)
New upstream version 4.8
Diffstat (limited to 'gnulib-tests/getcwd-lgpl.c')
-rw-r--r--gnulib-tests/getcwd-lgpl.c15
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;
}