summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/src/misc
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-02-06 11:40:35 +0100
committerwolfbeast <mcwerewolf@gmail.com>2018-02-06 11:40:35 +0100
commit7c728b3c7680662fc4e92b5d03697b8339560b08 (patch)
tree4a0da02f99913e0d52acd52067ad5a7be29e99a3 /nsprpub/pr/src/misc
parent13e9a0c06d35bb02d211df873c105a350aeab8eb (diff)
downloadUXP-7c728b3c7680662fc4e92b5d03697b8339560b08.tar
UXP-7c728b3c7680662fc4e92b5d03697b8339560b08.tar.gz
UXP-7c728b3c7680662fc4e92b5d03697b8339560b08.tar.lz
UXP-7c728b3c7680662fc4e92b5d03697b8339560b08.tar.xz
UXP-7c728b3c7680662fc4e92b5d03697b8339560b08.zip
Update NSPR to 4.16
Diffstat (limited to 'nsprpub/pr/src/misc')
-rw-r--r--nsprpub/pr/src/misc/praton.c8
-rw-r--r--nsprpub/pr/src/misc/prnetdb.c49
-rw-r--r--nsprpub/pr/src/misc/prtime.c66
-rw-r--r--nsprpub/pr/src/misc/prtpool.c18
4 files changed, 78 insertions, 63 deletions
diff --git a/nsprpub/pr/src/misc/praton.c b/nsprpub/pr/src/misc/praton.c
index bff0cd151..80c0628cc 100644
--- a/nsprpub/pr/src/misc/praton.c
+++ b/nsprpub/pr/src/misc/praton.c
@@ -177,19 +177,21 @@ pr_inet_aton(const char *cp, PRUint32 *addr)
case 2: /*%< a.b -- 8.24 bits */
if (val > 0xffffffU)
return (0);
- val |= parts[0] << 24;
+ val |= (unsigned int)parts[0] << 24;
break;
case 3: /*%< a.b.c -- 8.8.16 bits */
if (val > 0xffffU)
return (0);
- val |= (parts[0] << 24) | (parts[1] << 16);
+ val |= ((unsigned int)parts[0] << 24) | ((unsigned int)parts[1] << 16);
break;
case 4: /*%< a.b.c.d -- 8.8.8.8 bits */
if (val > 0xffU)
return (0);
- val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
+ val |= ((unsigned int)parts[0] << 24) |
+ ((unsigned int)parts[1] << 16) |
+ ((unsigned int)parts[2] << 8);
break;
}
*addr = PR_htonl(val);
diff --git a/nsprpub/pr/src/misc/prnetdb.c b/nsprpub/pr/src/misc/prnetdb.c
index b2f6e435b..affebf6ac 100644
--- a/nsprpub/pr/src/misc/prnetdb.c
+++ b/nsprpub/pr/src/misc/prnetdb.c
@@ -1405,7 +1405,7 @@ PR_IMPLEMENT(PRStatus) PR_InitializeNetAddr(
PRStatus rv = PR_SUCCESS;
if (!_pr_initialized) _PR_ImplicitInitialization();
- if (val != PR_IpAddrNull) memset(addr, 0, sizeof(addr->inet));
+ if (val != PR_IpAddrNull) memset(addr, 0, sizeof(*addr));
addr->inet.family = AF_INET;
addr->inet.port = htons(port);
switch (val)
@@ -1483,18 +1483,20 @@ PR_IsNetAddrType(const PRNetAddr *addr, PRNetAddrValue val)
if (val == PR_IpAddrAny) {
if (_PR_IN6_IS_ADDR_UNSPECIFIED((PRIPv6Addr *)&addr->ipv6.ip)) {
return PR_TRUE;
- } else if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip)
- && _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)&addr->ipv6.ip)
- == htonl(INADDR_ANY)) {
- return PR_TRUE;
+ }
+ if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip)
+ && _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)&addr->ipv6.ip)
+ == htonl(INADDR_ANY)) {
+ return PR_TRUE;
}
} else if (val == PR_IpAddrLoopback) {
if (_PR_IN6_IS_ADDR_LOOPBACK((PRIPv6Addr *)&addr->ipv6.ip)) {
return PR_TRUE;
- } else if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip)
- && _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)&addr->ipv6.ip)
- == htonl(INADDR_LOOPBACK)) {
- return PR_TRUE;
+ }
+ if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip)
+ && _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)&addr->ipv6.ip)
+ == htonl(INADDR_LOOPBACK)) {
+ return PR_TRUE;
}
} else if (val == PR_IpAddrV4Mapped
&& _PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip)) {
@@ -1504,8 +1506,9 @@ PR_IsNetAddrType(const PRNetAddr *addr, PRNetAddrValue val)
if (addr->raw.family == AF_INET) {
if (val == PR_IpAddrAny && addr->inet.ip == htonl(INADDR_ANY)) {
return PR_TRUE;
- } else if (val == PR_IpAddrLoopback
- && addr->inet.ip == htonl(INADDR_LOOPBACK)) {
+ }
+ if (val == PR_IpAddrLoopback
+ && addr->inet.ip == htonl(INADDR_LOOPBACK)) {
return PR_TRUE;
}
}
@@ -1777,18 +1780,12 @@ PR_IMPLEMENT(PRUint64) PR_ntohll(PRUint64 n)
#ifdef IS_BIG_ENDIAN
return n;
#else
- PRUint64 tmp;
PRUint32 hi, lo;
- LL_L2UI(lo, n);
- LL_SHR(tmp, n, 32);
- LL_L2UI(hi, tmp);
+ lo = (PRUint32)n;
+ hi = (PRUint32)(n >> 32);
hi = PR_ntohl(hi);
lo = PR_ntohl(lo);
- LL_UI2L(n, lo);
- LL_SHL(n, n, 32);
- LL_UI2L(tmp, hi);
- LL_ADD(n, n, tmp);
- return n;
+ return ((PRUint64)lo << 32) + (PRUint64)hi;
#endif
} /* ntohll */
@@ -1797,18 +1794,12 @@ PR_IMPLEMENT(PRUint64) PR_htonll(PRUint64 n)
#ifdef IS_BIG_ENDIAN
return n;
#else
- PRUint64 tmp;
PRUint32 hi, lo;
- LL_L2UI(lo, n);
- LL_SHR(tmp, n, 32);
- LL_L2UI(hi, tmp);
+ lo = (PRUint32)n;
+ hi = (PRUint32)(n >> 32);
hi = htonl(hi);
lo = htonl(lo);
- LL_UI2L(n, lo);
- LL_SHL(n, n, 32);
- LL_UI2L(tmp, hi);
- LL_ADD(n, n, tmp);
- return n;
+ return ((PRUint64)lo << 32) + (PRUint64)hi;
#endif
} /* htonll */
diff --git a/nsprpub/pr/src/misc/prtime.c b/nsprpub/pr/src/misc/prtime.c
index 6735805d8..f03786096 100644
--- a/nsprpub/pr/src/misc/prtime.c
+++ b/nsprpub/pr/src/misc/prtime.c
@@ -279,8 +279,7 @@ static int IsLeapYear(PRInt16 year)
{
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return 1;
- else
- return 0;
+ return 0;
}
/*
@@ -495,6 +494,20 @@ PR_NormalizeTime(PRExplodedTime *time, PRTimeParamFn params)
#define MT_safe_localtime localtime_r
+#elif defined(_MSC_VER)
+
+/* Visual C++ has had localtime_s() since Visual C++ 2005. */
+
+static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result)
+{
+ errno_t err = localtime_s(result, clock);
+ if (err != 0) {
+ errno = err;
+ return NULL;
+ }
+ return result;
+}
+
#else
#define HAVE_LOCALTIME_MONITOR 1 /* We use 'monitor' to serialize our calls
@@ -580,6 +593,7 @@ PR_LocalTimeParameters(const PRExplodedTime *gmt)
PRTimeParameters retVal;
struct tm localTime;
+ struct tm *localTimeResult;
time_t secs;
PRTime secs64;
PRInt64 usecPerSec;
@@ -606,7 +620,12 @@ PR_LocalTimeParameters(const PRExplodedTime *gmt)
*/
secs = 86400L;
- (void) MT_safe_localtime(&secs, &localTime);
+ localTimeResult = MT_safe_localtime(&secs, &localTime);
+ PR_ASSERT(localTimeResult != NULL);
+ if (localTimeResult == NULL) {
+ /* Shouldn't happen. Use safe fallback for optimized builds. */
+ return PR_GMTParameters(gmt);
+ }
/* GMT is 00:00:00, 2nd of Jan. */
@@ -957,6 +976,7 @@ PR_ParseTimeStringToExplodedTime(
int hour = -1;
int min = -1;
int sec = -1;
+ struct tm *localTimeResult;
const char *rest = string;
@@ -1215,7 +1235,7 @@ PR_ParseTimeStringToExplodedTime(
if ((end - rest) > 2)
/* it is [0-9][0-9][0-9]+: */
break;
- else if ((end - rest) == 2)
+ if ((end - rest) == 2)
tmp_hour = ((rest[0]-'0')*10 +
(rest[1]-'0'));
else
@@ -1230,12 +1250,12 @@ PR_ParseTimeStringToExplodedTime(
if (end == rest)
/* no digits after first colon? */
break;
- else if ((end - rest) > 2)
+ if ((end - rest) > 2)
/* it is [0-9][0-9][0-9]+: */
break;
- else if ((end - rest) == 2)
+ if ((end - rest) == 2)
tmp_min = ((rest[0]-'0')*10 +
- (rest[1]-'0'));
+ (rest[1]-'0'));
else
tmp_min = (rest[0]-'0');
@@ -1253,7 +1273,7 @@ PR_ParseTimeStringToExplodedTime(
else if ((end - rest) > 2)
/* it is [0-9][0-9][0-9]+: */
break;
- else if ((end - rest) == 2)
+ if ((end - rest) == 2)
tmp_sec = ((rest[0]-'0')*10 +
(rest[1]-'0'));
else
@@ -1287,7 +1307,7 @@ PR_ParseTimeStringToExplodedTime(
rest = end;
break;
}
- else if ((*end == '/' || *end == '-') &&
+ if ((*end == '/' || *end == '-') &&
end[1] >= '0' && end[1] <= '9')
{
/* Perhaps this is 6/16/95, 16/6/95, 6-16-95, or 16-6-95
@@ -1618,7 +1638,11 @@ PR_ParseTimeStringToExplodedTime(
zone_offset for the date we are parsing is the same as
the zone offset on 00:00:00 2 Jan 1970 GMT. */
secs = 86400;
- (void) MT_safe_localtime(&secs, &localTime);
+ localTimeResult = MT_safe_localtime(&secs, &localTime);
+ PR_ASSERT(localTimeResult != NULL);
+ if (localTimeResult == NULL) {
+ return PR_FAILURE;
+ }
zone_offset = localTime.tm_min
+ 60 * localTime.tm_hour
+ 1440 * (localTime.tm_mday - 2);
@@ -1989,24 +2013,22 @@ pr_WeekOfYear(const PRExplodedTime* time, unsigned int firstDayOfWeek)
dayOfWeek = time->tm_wday - firstDayOfWeek;
if (dayOfWeek < 0)
dayOfWeek += 7;
-
- dayOfYear = time->tm_yday - dayOfWeek;
+ dayOfYear = time->tm_yday - dayOfWeek;
if( dayOfYear <= 0 )
{
/* If dayOfYear is <= 0, it is in the first partial week of the year. */
return 0;
}
- else
- {
- /* Count the number of full weeks ( dayOfYear / 7 ) then add a week if there
- * are any days left over ( dayOfYear % 7 ). Because we are only counting to
- * the first day of the week containing the given time, rather than to the
- * actual day representing the given time, any days in week 0 will be "absorbed"
- * as extra days in the given week.
- */
- return (dayOfYear / 7) + ( (dayOfYear % 7) == 0 ? 0 : 1 );
- }
+
+ /* Count the number of full weeks ( dayOfYear / 7 ) then add a week if there
+ * are any days left over ( dayOfYear % 7 ). Because we are only counting to
+ * the first day of the week containing the given time, rather than to the
+ * actual day representing the given time, any days in week 0 will be "absorbed"
+ * as extra days in the given week.
+ */
+ return (dayOfYear / 7) + ( (dayOfYear % 7) == 0 ? 0 : 1 );
+
}
diff --git a/nsprpub/pr/src/misc/prtpool.c b/nsprpub/pr/src/misc/prtpool.c
index 0671cc19b..c2cc9c803 100644
--- a/nsprpub/pr/src/misc/prtpool.c
+++ b/nsprpub/pr/src/misc/prtpool.c
@@ -862,16 +862,16 @@ PR_QueueJob_Connect(PRThreadPool *tpool, PRJobIoDesc *iod,
if ((rv == PR_FAILURE) && ((err = PR_GetError()) == PR_IN_PROGRESS_ERROR)){
/* connection pending */
return(queue_io_job(tpool, iod, fn, arg, joinable, JOB_IO_CONNECT));
- } else {
- /*
- * connection succeeded or failed; add to jobq right away
- */
- if (rv == PR_FAILURE)
- iod->error = err;
- else
- iod->error = 0;
- return(PR_QueueJob(tpool, fn, arg, joinable));
}
+ /*
+ * connection succeeded or failed; add to jobq right away
+ */
+ if (rv == PR_FAILURE)
+ iod->error = err;
+ else
+ iod->error = 0;
+ return(PR_QueueJob(tpool, fn, arg, joinable));
+
}
/* queue a job, when a timer expires */