1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-03 14:52:21 +02:00

Add TIME parameter debug type.

Previously we were using int64_t to debug time_t but this may not be right depending on how the compiler represents time_t, e.g. it could be a float.

Since a mismatch would have caused a compiler error we are not worried that this has actually happened, and anyway the worst case is that the debug log would be wonky.

The primary benefit, aside from correctness, is that it makes choosing a parameter debug type for time_t obvious.
This commit is contained in:
David Steele 2019-11-08 09:46:00 -05:00
parent eca00e0be0
commit edcc7306a3
11 changed files with 50 additions and 9 deletions

View File

@ -38,11 +38,11 @@ restoreFile(
FUNCTION_LOG_PARAM(STRING, pgFileChecksum);
FUNCTION_LOG_PARAM(BOOL, pgFileZero);
FUNCTION_LOG_PARAM(UINT64, pgFileSize);
FUNCTION_LOG_PARAM(INT64, pgFileModified);
FUNCTION_LOG_PARAM(TIME, pgFileModified);
FUNCTION_LOG_PARAM(MODE, pgFileMode);
FUNCTION_LOG_PARAM(STRING, pgFileUser);
FUNCTION_LOG_PARAM(STRING, pgFileGroup);
FUNCTION_LOG_PARAM(INT64, copyTimeBegin);
FUNCTION_LOG_PARAM(TIME, copyTimeBegin);
FUNCTION_LOG_PARAM(BOOL, delta);
FUNCTION_LOG_PARAM(BOOL, deltaForce);
FUNCTION_TEST_PARAM(STRING, cipherPass);

View File

@ -186,6 +186,11 @@ size_t typeToLog(const char *typeName, char *buffer, size_t bufferSize);
#define FUNCTION_LOG_SSIZE_FORMAT(value, buffer, bufferSize) \
cvtSSizeToZ(value, buffer, bufferSize)
#define FUNCTION_LOG_TIME_TYPE \
time_t
#define FUNCTION_LOG_TIME_FORMAT(value, buffer, bufferSize) \
cvtTimeToZ(value, buffer, bufferSize)
#define FUNCTION_LOG_UINT_TYPE \
unsigned int
#define FUNCTION_LOG_UINT_FORMAT(value, buffer, bufferSize) \

View File

@ -9,6 +9,7 @@ Convert Base Data Types
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "common/debug.h"
#include "common/type/convert.h"
@ -380,6 +381,28 @@ cvtSSizeToZ(ssize_t value, char *buffer, size_t bufferSize)
FUNCTION_TEST_RETURN(result);
}
/***********************************************************************************************************************************
Convert time to zero-terminated string
***********************************************************************************************************************************/
size_t
cvtTimeToZ(time_t value, char *buffer, size_t bufferSize)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(TIME, value);
FUNCTION_TEST_PARAM_P(CHARDATA, buffer);
FUNCTION_TEST_PARAM(SIZE, bufferSize);
FUNCTION_TEST_END();
ASSERT(buffer != NULL);
size_t result = strftime(buffer, bufferSize, "%s", gmtime(&value));
if (result == 0)
THROW(AssertError, "buffer overflow");
FUNCTION_TEST_RETURN(result);
}
/***********************************************************************************************************************************
Convert uint to zero-terminated string
***********************************************************************************************************************************/

View File

@ -36,6 +36,8 @@ mode_t cvtZToMode(const char *value);
size_t cvtSizeToZ(size_t value, char *buffer, size_t bufferSize);
size_t cvtSSizeToZ(ssize_t value, char *buffer, size_t bufferSize);
size_t cvtTimeToZ(time_t value, char *buffer, size_t bufferSize);
size_t cvtUIntToZ(unsigned int value, char *buffer, size_t bufferSize);
unsigned int cvtZToUInt(const char *value);
unsigned int cvtZToUIntBase(const char *value, int base);

View File

@ -420,7 +420,7 @@ storagePosixNewWrite(
FUNCTION_LOG_PARAM(MODE, modePath);
FUNCTION_LOG_PARAM(STRING, user);
FUNCTION_LOG_PARAM(STRING, group);
FUNCTION_LOG_PARAM(INT64, timeModified);
FUNCTION_LOG_PARAM(TIME, timeModified);
FUNCTION_LOG_PARAM(BOOL, createPath);
FUNCTION_LOG_PARAM(BOOL, syncFile);
FUNCTION_LOG_PARAM(BOOL, syncPath);

View File

@ -231,7 +231,7 @@ storageWritePosixNew(
FUNCTION_LOG_PARAM(MODE, modePath);
FUNCTION_LOG_PARAM(STRING, user);
FUNCTION_LOG_PARAM(STRING, group);
FUNCTION_LOG_PARAM(INT64, timeModified);
FUNCTION_LOG_PARAM(TIME, timeModified);
FUNCTION_LOG_PARAM(BOOL, createPath);
FUNCTION_LOG_PARAM(BOOL, syncFile);
FUNCTION_LOG_PARAM(BOOL, syncPath);

View File

@ -150,7 +150,7 @@ storageRemoteNewWrite(
FUNCTION_LOG_PARAM(MODE, modePath);
FUNCTION_LOG_PARAM(STRING, user);
FUNCTION_LOG_PARAM(STRING, group);
FUNCTION_LOG_PARAM(INT64, timeModified);
FUNCTION_LOG_PARAM(TIME, timeModified);
FUNCTION_LOG_PARAM(BOOL, createPath);
FUNCTION_LOG_PARAM(BOOL, syncFile);
FUNCTION_LOG_PARAM(BOOL, syncPath);

View File

@ -176,7 +176,7 @@ storageWriteRemoteNew(
FUNCTION_LOG_PARAM(MODE, modePath);
FUNCTION_LOG_PARAM(STRING, user);
FUNCTION_LOG_PARAM(STRING, group);
FUNCTION_LOG_PARAM(INT64, timeModified);
FUNCTION_LOG_PARAM(TIME, timeModified);
FUNCTION_LOG_PARAM(BOOL, createPath);
FUNCTION_LOG_PARAM(BOOL, syncFile);
FUNCTION_LOG_PARAM(BOOL, syncPath);

View File

@ -117,7 +117,7 @@ static String *
storageS3DateTime(time_t authTime)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(INT64, authTime);
FUNCTION_TEST_PARAM(TIME, authTime);
FUNCTION_TEST_END();
char buffer[ISO_8601_DATE_TIME_SIZE + 1];
@ -735,7 +735,7 @@ storageS3NewWrite(
FUNCTION_LOG_PARAM(MODE, modePath);
FUNCTION_LOG_PARAM(STRING, user);
FUNCTION_LOG_PARAM(STRING, group);
FUNCTION_LOG_PARAM(INT64, timeModified);
FUNCTION_LOG_PARAM(TIME, timeModified);
FUNCTION_LOG_PARAM(BOOL, createPath);
FUNCTION_LOG_PARAM(BOOL, syncFile);
FUNCTION_LOG_PARAM(BOOL, syncPath);

View File

@ -151,7 +151,7 @@ unit:
# ----------------------------------------------------------------------------------------------------------------------------
- name: type-convert
total: 9
total: 10
coverage:
common/type/convert: full

View File

@ -108,6 +108,17 @@ testRun(void)
TEST_RESULT_STR(buffer, "-9999", " check buffer");
}
// *****************************************************************************************************************************
if (testBegin("cvtTimeToZ()"))
{
char buffer[STACK_TRACE_PARAM_MAX];
TEST_ERROR(cvtTimeToZ(9999, buffer, 4), AssertError, "buffer overflow");
TEST_RESULT_UINT(cvtTimeToZ(1573222014, buffer, STACK_TRACE_PARAM_MAX), 10, "convert time to string");
TEST_RESULT_STR(buffer, "1573222014", " check buffer");
}
// *****************************************************************************************************************************
if (testBegin("cvtUIntToZ() and cvtZToUInt()"))
{