Skip to content

Commit 4df35d2

Browse files
committed
libpcp: fix endian issue in big-endian __pmTimestamp writing
Mirror an earlier endian fix in the reading code for big-endian platforms for writing __pmTimestamp structures. Affects v3 log writing only, and big endian platforms only. Some minor code cleanup also; fix an unused-function warning on big endian build machines and keep the various timestamp get/put routines together in logmeta.c for easier cross-referencing. Resolves Red Hat bug RHEL-69722 Resolves github issue #2110
1 parent 5c4322e commit 4df35d2

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/libpcp/src/endian.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ __ntohpmLabel(pmLabel * const label)
7777
}
7878
#endif
7979

80+
#ifndef __htonpmValueBlock
8081
static void
8182
__htonpmTimespec(pmTimespec * const tsp)
8283
{
8384
__htonll((char *)&tsp->tv_sec);
8485
__htonll((char *)&tsp->tv_nsec);
8586
}
8687

87-
#ifndef __htonpmValueBlock
8888
static void
8989
htonEventArray(pmValueBlock * const vb, int highres)
9090
{

src/libpcp/src/logmeta.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,17 +1823,6 @@ __pmLoadTimestamp(const __int32_t *buf, __pmTimestamp *tsp)
18231823
}
18241824
}
18251825

1826-
void
1827-
__pmLoadTimeval(const __int32_t *buf, __pmTimestamp *tsp)
1828-
{
1829-
tsp->sec = (__int32_t)ntohl(buf[0]);
1830-
tsp->nsec = ntohl(buf[1]) * 1000;
1831-
if (pmDebugOptions.logmeta && pmDebugOptions.desperate) {
1832-
fprintf(stderr, "__pmLoadTimeval: network(%08x %08x usec)", buf[0], buf[1]);
1833-
fprintf(stderr, " -> %" FMT_INT64 ".%09d (%llx %x nsec)\n", tsp->sec, tsp->nsec, (long long)tsp->sec, tsp->nsec);
1834-
}
1835-
}
1836-
18371826
void
18381827
__pmPutTimestamp(const __pmTimestamp *tsp, __int32_t *buf)
18391828
{
@@ -1845,15 +1834,31 @@ __pmPutTimestamp(const __pmTimestamp *tsp, __int32_t *buf)
18451834
* need to dodge endian issues here ... want the MSB 32-bits of sec
18461835
* in buf[0] and the LSB 32 bits of sec in buf[1]
18471836
*/
1848-
buf[0] = (stamp.sec >> 32) & 0xffffffff;
1849-
buf[1] = stamp.sec & 0xffffffff;
1837+
#if __BYTE_ORDER == __LITTLE_ENDIAN
1838+
buf[0] = (__int32_t)((__int64_t)(stamp.sec >> 32));
1839+
buf[1] = (__int32_t)((__int64_t)(stamp.sec & 0x00000000ffffffffLL));
1840+
#else
1841+
buf[1] = (__int32_t)((__int64_t)(stamp.sec >> 32));
1842+
buf[0] = (__int32_t)((__int64_t)(stamp.sec & 0x00000000ffffffffLL));
1843+
#endif
18501844
buf[2] = stamp.nsec;
18511845
if (pmDebugOptions.logmeta && pmDebugOptions.desperate) {
18521846
fprintf(stderr, "__pmPutTimestamp: %" FMT_INT64 ".%09d (%llx %x nsec)", tsp->sec, tsp->nsec, (long long)tsp->sec, tsp->nsec);
18531847
fprintf(stderr, " -> network(%08x%08x %08x nsec)\n", buf[0], buf[1], buf[2]);
18541848
}
18551849
}
18561850

1851+
void
1852+
__pmLoadTimeval(const __int32_t *buf, __pmTimestamp *tsp)
1853+
{
1854+
tsp->sec = (__int32_t)ntohl(buf[0]);
1855+
tsp->nsec = ntohl(buf[1]) * 1000;
1856+
if (pmDebugOptions.logmeta && pmDebugOptions.desperate) {
1857+
fprintf(stderr, "__pmLoadTimeval: network(%08x %08x usec)", buf[0], buf[1]);
1858+
fprintf(stderr, " -> %" FMT_INT64 ".%09d (%llx %x nsec)\n", tsp->sec, tsp->nsec, (long long)tsp->sec, tsp->nsec);
1859+
}
1860+
}
1861+
18571862
void
18581863
__pmPutTimeval(const __pmTimestamp *tsp, __int32_t *buf)
18591864
{

0 commit comments

Comments
 (0)