[libc-commits] [PATCH] D107792: [libc] add strtoll function and backend

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Aug 10 11:46:02 PDT 2021


michaelrj marked 3 inline comments as done.
michaelrj added a comment.

The relevant line from the specification is "The functions atof, atoi, atol, and atoll need not affect the value of the integer expression errno on an error. If the value of the result cannot be represented, the behavior is undefined." From what I can tell that means that we aren't required to set the errno at any time, since if you pass it an out of range number then that is undefined behavior. However, implementations in other libcs do set `errno` to `ERANGE` when `atoi` is passed a number that is greater than 2^63. 
Since this follows the specification, matches expected behavior from other libcs, and simplifies implementation, I think this is the best way forward.



================
Comment at: libc/src/__support/stdlib_utils.h:103
+  if (str_end != nullptr)
+    *str_end = (char *)(src);
+  if (result_sign == '+')
----------------
sivachandra wrote:
> michaelrj wrote:
> > This line gives me compiler warnings due to casting from a `const char*` to a `char*` but the specification says that `str_end` is not const. Is there a better way to do this or alternately a way to suppress the compiler warnings?
> `*str_end = const_cast<char *>(src);` ?
ah yes, that fixed it. Thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107792



More information about the libc-commits mailing list