[libc-commits] [PATCH] D91551: Initial commit of mktime.

Raman Tenneti via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Nov 30 17:08:29 PST 2020


rtenneti marked an inline comment as done.
rtenneti added inline comments.


================
Comment at: libc/src/time/mktime.cpp:64
+      return (time_t)(-1);
+  }
+
----------------
sivachandra wrote:
> jeffbailey wrote:
> > rtenneti wrote:
> > > sivachandra wrote:
> > > > Could we do this overflow check in a more general fashion? For example, we can find a `maxYears` that can fit in `TIME_T_MAX` (I am making up `TIME_T_MAX`). After that, assuming valid inputs for other fields, we can progressively check if the result will fit in `time_t`.
> > > Add a TODO to investigate the above idea.
> > Is the TODO still necessary with the creation of outOfRange() that sets errno and returns -1?
> Along with the above comment about checking for invalid input, what I meant was this: As we start accumulating the seconds, we should be able to check if the next amount of seconds to be added can lead to an overflow. If it does, return the overflow value. If not keep accumulating. The benefit is that, we don't have to validate every input, and also do need the special cases for `sizeof(time_t) == 4`.
Added a TODO. The above is my intetntion when implementing handle of invalid data (of some one passing INT_MAX in either seconds, minutes, hours ...).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91551



More information about the libc-commits mailing list