diff --git a/Userland/Libraries/LibC/string.cpp b/Userland/Libraries/LibC/string.cpp index 3847afb6dc..5adfe173ae 100644 --- a/Userland/Libraries/LibC/string.cpp +++ b/Userland/Libraries/LibC/string.cpp @@ -357,7 +357,7 @@ int sys_nerr = EMAXERRNO; int strerror_r(int errnum, char* buf, size_t buflen) { auto saved_errno = errno; - if (errnum >= EMAXERRNO) { + if (errnum < 0 || errnum >= EMAXERRNO) { auto rc = strlcpy(buf, "unknown error", buflen); if (rc >= buflen) dbgln("strerror_r(): Invalid error number '{}' specified and the output buffer is too small.", errnum);