diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index 6081a44..55cd181 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -1840,10 +1840,10 @@ from_char_parse_int_len(int *dest, char **src, const int len, FormatNode *node) long result; char copy[DCH_MAX_ITEM_SIZ + 1]; char *init = *src; + int used; Assert(len <= DCH_MAX_ITEM_SIZ); - strncpy(copy, *src, len); - copy[len] = '\0'; + used = (int) strlcpy(copy, *src, len + 1); if (S_FM(node->suffix) || is_next_separator(node)) { @@ -1862,16 +1862,15 @@ from_char_parse_int_len(int *dest, char **src, const int len, FormatNode *node) * of the string, and convert those. */ char *last; - int used; - if (strlen(copy) < len) + if (used < len) ereport(ERROR, (errcode(ERRCODE_INVALID_DATETIME_FORMAT), errmsg("source string too short for \"%s\" formatting field", node->key->name), errdetail("Field requires %d characters, but only %d " "remain.", - len, (int) strlen(copy)), + len, used), errhint("If your source string is not fixed-width, try " "using the \"FM\" modifier."))); @@ -2021,8 +2020,7 @@ from_char_seq_search(int *dest, char **src, char **array, int type, int max, char copy[DCH_MAX_ITEM_SIZ + 1]; Assert(max <= DCH_MAX_ITEM_SIZ); - strncpy(copy, *src, max); - copy[max] = '\0'; + strlcpy(copy, *src, max + 1); ereport(ERROR, (errcode(ERRCODE_INVALID_DATETIME_FORMAT),