* [GCC-10][committed] libphobos: Fix std.path.expandTilde raising onOutOfMemory
@ 2022-12-13 23:05 Iain Buclaw
0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2022-12-13 23:05 UTC (permalink / raw)
To: gcc-patches; +Cc: Iain Buclaw
Hi,
This patch backports from mainline a fix for std.path.expandTilde
erroneously raising onOutOfMemory after failed call to `getpwnam_r()'.
Regression tested on x86_64-linux-gnu/-m32/-mx32, committed to
releases/gcc-10 branch.
Regards,
Iain.
---
libphobos/ChangeLog:
* src/std/path.d (expandTilde): Handle more errno codes that could be
left set by getpwnam_r.
---
libphobos/src/std/path.d | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/libphobos/src/std/path.d b/libphobos/src/std/path.d
index 4a435efba6c..d250953ee1c 100644
--- a/libphobos/src/std/path.d
+++ b/libphobos/src/std/path.d
@@ -3850,7 +3850,7 @@ string expandTilde(string inputPath) nothrow
version (Posix)
{
import core.exception : onOutOfMemoryError;
- import core.stdc.errno : errno, ERANGE;
+ import core.stdc.errno : errno, EBADF, ENOENT, EPERM, ERANGE, ESRCH;
import core.stdc.stdlib : malloc, free, realloc;
/* Joins a path from a C string to the remainder of path.
@@ -3950,7 +3950,7 @@ string expandTilde(string inputPath) nothrow
scope(exit) free(extra_memory);
passwd result;
- while (1)
+ loop: while (1)
{
extra_memory = cast(char*) realloc(extra_memory, extra_memory_size * char.sizeof);
if (extra_memory == null)
@@ -3969,10 +3969,23 @@ string expandTilde(string inputPath) nothrow
break;
}
- if (errno != ERANGE &&
+ switch (errno)
+ {
+ case ERANGE:
// On BSD and OSX, errno can be left at 0 instead of set to ERANGE
- errno != 0)
- onOutOfMemoryError();
+ case 0:
+ break;
+
+ case ENOENT:
+ case ESRCH:
+ case EBADF:
+ case EPERM:
+ // The given name or uid was not found.
+ break loop;
+
+ default:
+ onOutOfMemoryError();
+ }
// extra_memory isn't large enough
import core.checkedint : mulu;
--
2.37.2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-12-13 23:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-13 23:05 [GCC-10][committed] libphobos: Fix std.path.expandTilde raising onOutOfMemory Iain Buclaw
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).