diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 2af87ee3bd..d81aac369f 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -68,6 +68,7 @@ #include "access/transam.h" #include "access/xact.h" +#include "common/string.h" #include "libpq/libpq.h" #include "libpq/pqformat.h" #include "mb/pg_wchar.h" @@ -177,7 +178,6 @@ static void set_errdata_field(MemoryContextData *cxt, char **ptr, const char *st static void write_console(const char *line, int len); static void setup_formatted_log_time(void); static void setup_formatted_start_time(void); -static const char *process_log_prefix_padding(const char *p, int *padding); static void log_line_prefix(StringInfo buf, ErrorData *edata); static void write_csvlog(ErrorData *edata); static void send_message_to_server_log(ErrorData *edata); @@ -2338,41 +2338,6 @@ setup_formatted_start_time(void) pg_localtime(&stamp_time, log_timezone)); } -/* - * process_log_prefix_padding --- helper function for processing the format - * string in log_line_prefix - * - * Note: This function returns NULL if it finds something which - * it deems invalid in the format string. - */ -static const char * -process_log_prefix_padding(const char *p, int *ppadding) -{ - int paddingsign = 1; - int padding = 0; - - if (*p == '-') - { - p++; - - if (*p == '\0') /* Did the buf end in %- ? */ - return NULL; - paddingsign = -1; - } - - /* generate an int version of the numerical string */ - while (*p >= '0' && *p <= '9') - padding = padding * 10 + (*p++ - '0'); - - /* format is invalid if it ends with the padding number */ - if (*p == '\0') - return NULL; - - padding *= paddingsign; - *ppadding = padding; - return p; -} - /* * Format tag info for log lines; append to the provided buffer. */ @@ -2427,8 +2392,7 @@ log_line_prefix(StringInfo buf, ErrorData *edata) /* * Process any formatting which may exist after the '%'. Note that - * process_log_prefix_padding moves p past the padding number if it - * exists. + * p will points the past the padding number if it exists. * * Note: Since only '-', '0' to '9' are valid formatting characters we * can do a quick check here to pre-check for formatting. If the char @@ -2441,8 +2405,23 @@ log_line_prefix(StringInfo buf, ErrorData *edata) */ if (*p > '9') padding = 0; - else if ((p = process_log_prefix_padding(p, &padding)) == NULL) - break; + else if (*p == '-' ? isdigit(p[1]) : isdigit(p[0])) + { + char *endptr; + padding = strtol(p, &endptr, 10); + if (p == endptr || *endptr == '\0') + break; + p = endptr; + } + else + if (*p == '-') + { + p++; + padding = -1; + } + else + padding = 0; + /* process the option */ switch (*p)