comparison mercurial/util.py @ 28864:b0811a9fe67c

date: fix boundary check of negative integer
author Florent Gallaire <fgallaire@gmail.com>
date Tue, 12 Apr 2016 00:30:28 +0200
parents 68a946e83188
children 16255662446d
comparison
equal deleted inserted replaced
28863:6e06fbee9244 28864:b0811a9fe67c
1593 format = format.replace("%1", "%c%02d" % (sign, q)) 1593 format = format.replace("%1", "%c%02d" % (sign, q))
1594 format = format.replace("%2", "%02d" % r) 1594 format = format.replace("%2", "%02d" % r)
1595 d = t - tz 1595 d = t - tz
1596 if d > 0x7fffffff: 1596 if d > 0x7fffffff:
1597 d = 0x7fffffff 1597 d = 0x7fffffff
1598 elif d < -0x7fffffff: 1598 elif d < -0x80000000:
1599 d = -0x7fffffff 1599 d = -0x80000000
1600 # Never use time.gmtime() and datetime.datetime.fromtimestamp() 1600 # Never use time.gmtime() and datetime.datetime.fromtimestamp()
1601 # because they use the gmtime() system call which is buggy on Windows 1601 # because they use the gmtime() system call which is buggy on Windows
1602 # for negative values. 1602 # for negative values.
1603 t = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=d) 1603 t = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=d)
1604 s = t.strftime(format) 1604 s = t.strftime(format)
1718 raise Abort(_('invalid date: %r') % date) 1718 raise Abort(_('invalid date: %r') % date)
1719 # validate explicit (probably user-specified) date and 1719 # validate explicit (probably user-specified) date and
1720 # time zone offset. values must fit in signed 32 bits for 1720 # time zone offset. values must fit in signed 32 bits for
1721 # current 32-bit linux runtimes. timezones go from UTC-12 1721 # current 32-bit linux runtimes. timezones go from UTC-12
1722 # to UTC+14 1722 # to UTC+14
1723 if abs(when) > 0x7fffffff: 1723 if when < -0x80000000 or when > 0x7fffffff:
1724 raise Abort(_('date exceeds 32 bits: %d') % when) 1724 raise Abort(_('date exceeds 32 bits: %d') % when)
1725 if offset < -50400 or offset > 43200: 1725 if offset < -50400 or offset > 43200:
1726 raise Abort(_('impossible time zone offset: %d') % offset) 1726 raise Abort(_('impossible time zone offset: %d') % offset)
1727 return when, offset 1727 return when, offset
1728 1728