Skip to content

Commit

Permalink
Bug 751984 - PATCH: Honour SOURCE_DATE_EPOCH environment variable for…
Browse files Browse the repository at this point in the history
… reproducible output
  • Loading branch information
Dimitri van Heesch committed Jul 19, 2015
1 parent 4116648 commit b31266c
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
6 changes: 6 additions & 0 deletions qtools/qcstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ ulong QCString::toULong(bool *ok) const
return s.toULong(ok);
}

uint64 QCString::toUInt64(bool *ok) const
{
QString s(data());
return s.toUInt64(ok);
}

QCString &QCString::setNum(short n)
{
return setNum((long)n);
Expand Down
1 change: 1 addition & 0 deletions qtools/qcstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class QCString
uint toUInt( bool *ok=0 ) const;
long toLong( bool *ok=0 ) const;
ulong toULong( bool *ok=0 ) const;
uint64 toUInt64( bool *ok=0 ) const;
QCString &setNum(short n);
QCString &setNum(ushort n);
QCString &setNum(int n);
Expand Down
54 changes: 54 additions & 0 deletions qtools/qstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13934,6 +13934,60 @@ ulong QString::toULong( bool *ok, int base ) const
return is_ok ? val : 0;
}

/*!
Returns the string converted to an <code>unsigned long</code>
value.
If \a ok is non-null, \a *ok is set to TRUE if there are no
conceivable errors, and FALSE if the string is not a number at all,
or if it has trailing garbage.
*/

uint64 QString::toUInt64( bool *ok, int base ) const
{
const QChar *p = unicode();
uint64 val=0;
int l = length();
const uint64 max_mult = 1844674407370955161ULL; // ULLONG_MAX/10, rounded down
bool is_ok = FALSE;
if ( !p )
goto bye;
while ( l && p->isSpace() ) // skip leading space
l--,p++;
if ( *p == '+' )
l--,p++;

// NOTE: toULong() code is similar
if ( !l || !ok_in_base(*p,base) )
goto bye;
while ( l && ok_in_base(*p,base) ) {
l--;
uint dv;
if ( p->isDigit() ) {
dv = p->digitValue();
} else {
if ( *p >= 'a' && *p <= 'z' )
dv = *p - 'a' + 10;
else
dv = *p - 'A' + 10;
}
if ( val > max_mult || (val == max_mult && dv > (ULLONG_MAX%base)) )
goto bye;
val = base*val + dv;
p++;
}

while ( l && p->isSpace() ) // skip trailing space
l--,p++;
if ( !l )
is_ok = TRUE;
bye:
if ( ok )
*ok = is_ok;
return is_ok ? val : 0;
}


/*!
Returns the string converted to a <code>short</code> value.
Expand Down
1 change: 1 addition & 0 deletions qtools/qstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ class Q_EXPORT QString
uint toUInt( bool *ok=0, int base=10 ) const;
long toLong( bool *ok=0, int base=10 ) const;
ulong toULong( bool *ok=0, int base=10 ) const;
uint64 toUInt64( bool *ok=0, int base=10 ) const;
float toFloat( bool *ok=0 ) const;
double toDouble( bool *ok=0 ) const;

Expand Down
30 changes: 30 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <ctype.h>
#include <errno.h>
#include <math.h>
#include <limits.h>

#include "md5.h"

Expand Down Expand Up @@ -2472,6 +2473,35 @@ QCString fileToString(const char *name,bool filter,bool isSourceCode)
QCString dateToString(bool includeTime)
{
QDateTime current = QDateTime::currentDateTime();
QCString sourceDateEpoch = portable_getenv("SOURCE_DATE_EPOCH");
if (!sourceDateEpoch.isEmpty())
{
bool ok;
uint64 epoch = sourceDateEpoch.toUInt64(&ok);
if (!ok)
{
static bool warnedOnce=FALSE;
if (!warnedOnce)
{
warn_uncond("Environment variable SOURCE_DATE_EPOCH does not contain a valid number; value is '%s'\n",
sourceDateEpoch.data());
warnedOnce=TRUE;
}
}
else if (epoch>UINT_MAX)
{
static bool warnedOnce=FALSE;
if (!warnedOnce)
{
warn_uncond("Environment variable SOURCE_DATA_EPOCH must have a value smaller than or equal to %llu; actual value %llu\n",UINT_MAX,epoch);
warnedOnce=TRUE;
}
}
else // all ok, replace current time with epoch value
{
current.setTime_t((ulong)epoch); // TODO: add support for 64bit epoch value
}
}
return theTranslator->trDateTime(current.date().year(),
current.date().month(),
current.date().day(),
Expand Down

0 comments on commit b31266c

Please sign in to comment.