From 7fcf217b682ea32d2f6baeca75e3474e9003b4f4 Mon Sep 17 00:00:00 2001 From: Max Starkov Date: Wed, 9 Nov 2022 16:47:07 +0500 Subject: [PATCH 1/2] change pg type to tds type --- src/deparse.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/deparse.c b/src/deparse.c index baa6ef2..53c1272 100644 --- a/src/deparse.c +++ b/src/deparse.c @@ -712,8 +712,8 @@ static char* postgresql_type_to_tds_type(const char* postgresql_type) const char* tds_type_local = "datetime2"; size_t len = strlen(tds_type_local); - tds_type = palloc(len); - strncpy(tds_type, tds_type_local, len); + tds_type = (char *) palloc((len + 1) * sizeof(char)); + sprintf(tds_type, "%s", tds_type_local); } /* if no mapping defined, just copy postgresql type */ @@ -721,8 +721,8 @@ static char* postgresql_type_to_tds_type(const char* postgresql_type) { size_t len = strlen(postgresql_type); - tds_type = palloc(len); - strncpy(tds_type, postgresql_type, len); + tds_type = (char *) palloc((len + 1) * sizeof(char)); + sprintf(tds_type, "%s", postgresql_type); } return tds_type; From fbcc58e5f07c4db00714dfac6aadfedc7e723832 Mon Sep 17 00:00:00 2001 From: Max Starkov Date: Wed, 23 Nov 2022 22:44:53 +0500 Subject: [PATCH 2/2] use psprintf --- src/deparse.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/deparse.c b/src/deparse.c index 53c1272..9994483 100644 --- a/src/deparse.c +++ b/src/deparse.c @@ -709,20 +709,13 @@ static char* postgresql_type_to_tds_type(const char* postgresql_type) || strcmp(postgresql_type, "timestamp with time zone") == 0 || strcmp(postgresql_type, "timestamp without time zone") == 0) { - const char* tds_type_local = "datetime2"; - size_t len = strlen(tds_type_local); - - tds_type = (char *) palloc((len + 1) * sizeof(char)); - sprintf(tds_type, "%s", tds_type_local); + tds_type = psprintf("%s", "datetime2"); } /* if no mapping defined, just copy postgresql type */ else { - size_t len = strlen(postgresql_type); - - tds_type = (char *) palloc((len + 1) * sizeof(char)); - sprintf(tds_type, "%s", postgresql_type); + tds_type = psprintf("%s", postgresql_type); } return tds_type;