Navigation Menu

Skip to content

Commit

Permalink
Compute overflow check value before overflowed
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 24, 2012
1 parent 780ab03 commit 502181f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ha_mroonga.cpp
Expand Up @@ -1507,11 +1507,12 @@ static int mrn_set_geometry(grn_ctx *ctx, grn_obj *buf,
static long long int mrn_tm_to_grn_time(struct tm *time, int usec)
{
MRN_DBUG_ENTER_FUNCTION();
bool before_epoch_time =
(time->tm_year >= (UNIX_EPOCH_TIME_YEAR - TM_YEAR_BASE));
long long int grn_time;
long long int sec = mktime(time);
bool failed = (sec == -1);
bool overflowed = (time->tm_year >= (UNIX_EPOCH_TIME_YEAR - TM_YEAR_BASE) &&
sec < 0);
bool overflowed = (before_epoch_time && sec < 0);
if (failed || overflowed) {
grn_time = 0;
} else {
Expand Down

0 comments on commit 502181f

Please sign in to comment.