From 68678b864ef68f0c0ce494d3f24ca6ed63f05422 Mon Sep 17 00:00:00 2001 From: rfm Date: Fri, 26 Jan 2024 14:12:01 +0000 Subject: [PATCH] Fix for millisecond timestamp info --- ChangeLog | 4 ++++ Postgres.m | 29 +++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index d87983c..f241ddf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2024-01-26 Richard Frith-Macdonald + + * Postgres.m: Fix error in parsing milliseconds in timestamp. + 2023-11-23 Richard Frith-Macdonald * SQLClient.h: New instance variables for timing lock waits. diff --git a/Postgres.m b/Postgres.m index b1ad06d..18c3b4b 100644 --- a/Postgres.m +++ b/Postgres.m @@ -192,10 +192,10 @@ newDateFromBuffer(const char *b, int l) i++; if (i >= l || !isdigit(b[i])) return nil; milliseconds = b[i++] - '0'; - milliseconds *=- 10; + milliseconds *= 10; if (i < l && isdigit(b[i])) milliseconds += b[i++] - '0'; - milliseconds *=- 10; + milliseconds *= 10; if (i < l && isdigit(b[i])) milliseconds += b[i++] - '0'; while (i < l && isdigit(b[i])) @@ -1302,8 +1302,24 @@ static inline unsigned int trim(char *str, unsigned len) if (d > 1) { - [self debug: @"%@ type:%d mod:%d size: %d\n", - keys[j], ftype[j], fmod[j], size]; +#if 0 + /* For even more debug we can write some of the + * data retrieved, but that may be a security + * issue. + */ + if (0 == fformat[j] && size <= 100) + { + [self debug: + @"%@ type:%d mod:%d size: %d %*.*s\n", + keys[j], ftype[j], fmod[j], size, + size, size, p]; + } + else +#endif + { + [self debug: @"%@ type:%d mod:%d size: %d\n", + keys[j], ftype[j], fmod[j], size]; + } } /* Often many rows will contain the same data in * one or more columns, so we check to see if the @@ -1843,7 +1859,8 @@ static inline unsigned int trim(char *str, unsigned len) type: ET_RDESC forMode: NSDefaultRunLoopMode all: YES]; - [self debug: @"Listen event on disconnected client, desc: %d", (int)data]; + [self debug: @"Listen event on disconnected client, desc: %d", + (int)(intptr_t)data]; } else { @@ -1855,7 +1872,7 @@ static inline unsigned int trim(char *str, unsigned len) strncpy(msg, PQerrorMessage(connection), sizeof(msg)-1); msg[sizeof(msg)-1] = '\0'; if (PQstatus(connection) != CONNECTION_OK - || PQsocket(connection) != (int)data) + || PQsocket(connection) != (int)(intptr_t)data) { /* The connection has been lost, so we must disconnect, * which will stop us receiving events on the descriptor.