[libc-commits] [PATCH] D147981: [LIBC] Fix `getrandom` success return value
Noah Goldstein via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Apr 11 12:13:17 PDT 2023
goldstein.w.n updated this revision to Diff 512544.
goldstein.w.n added a comment.
64 -> 61 (for prime) + comment explaining rationale
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147981/new/
https://reviews.llvm.org/D147981
Files:
libc/src/sys/random/linux/getrandom.cpp
libc/test/src/sys/random/linux/getrandom_test.cpp
Index: libc/test/src/sys/random/linux/getrandom_test.cpp
===================================================================
--- libc/test/src/sys/random/linux/getrandom_test.cpp
+++ libc/test/src/sys/random/linux/getrandom_test.cpp
@@ -29,6 +29,17 @@
libc_errno = 0;
}
+TEST(LlvmLibcGetRandomTest, ReturnsSize) {
+ static constexpr size_t SIZE = 8192;
+ uint8_t buf[SIZE];
+ // 1 + (i % 61) to get a decent spread of sizes without potentially difficult
+ // to reproduce random sizes or spending the time doing all values [0, SIZE).
+ for (size_t i = 0; i < SIZE; i += 1 + (i % 61)) {
+ // Without GRND_RANDOM set this should never fail.
+ ASSERT_EQ(__llvm_libc::getrandom(buf, i, 0), static_cast<ssize_t>(i));
+ }
+}
+
TEST(LlvmLibcGetRandomTest, PiEstimation) {
static constexpr size_t LIMIT = 10000000;
static constexpr double PI = 3.14159265358979;
Index: libc/src/sys/random/linux/getrandom.cpp
===================================================================
--- libc/src/sys/random/linux/getrandom.cpp
+++ libc/src/sys/random/linux/getrandom.cpp
@@ -23,7 +23,7 @@
libc_errno = -ret;
return -1;
}
- return 0;
+ return ret;
}
} // namespace __llvm_libc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147981.512544.patch
Type: text/x-patch
Size: 1206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230411/b9f1880f/attachment.bin>
More information about the libc-commits
mailing list