[libc-commits] [PATCH] D85615: [libc] Add strtok implementation.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Aug 10 20:26:10 PDT 2020


sivachandra added inline comments.


================
Comment at: libc/test/src/string/strtok_test.cpp:61
+  token = __llvm_libc::strtok(nullptr, "_:,_");
+  ASSERT_STREQ(token, nullptr);
+  // Subsequent calls after hitting the end of the string should also return
----------------
cgyurgyik wrote:
> sivachandra wrote:
> > Does `strtok` as implemented above ever return `nullptr`?  This got me to go look why `ASSERT_STREQ` is happy. It turns out, our `STREQ` comparison first converts the string to `llvm::StringRef` which makes an empty string compare equal to a nullptr! That needs fixing separately.
> Do we want `strtok` to return `nullptr` in the case the null terminator is hit?
Yes. I would think that is what this text from the standard means:

//If no such character was found, there are no tokens in str at all, and the function returns a null pointer.
//

https://en.cppreference.com/w/c/string/byte/strtok


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85615/new/

https://reviews.llvm.org/D85615



More information about the libc-commits mailing list