mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Add use of asprintf()
Add asprintf(), pg_asprintf(), and psprintf() to simplify string allocation and composition. Replacement implementations taken from NetBSD. Reviewed-by: Álvaro Herrera <alvherre@2ndquadrant.com> Reviewed-by: Asif Naeem <anaeem.it@gmail.com>
This commit is contained in:
@ -127,12 +127,9 @@ main(void)
|
||||
{
|
||||
for (j = 0; times[j]; j++)
|
||||
{
|
||||
int length = strlen(dates[i])
|
||||
+ 1
|
||||
+ strlen(times[j])
|
||||
+ 1;
|
||||
char* t = malloc(length);
|
||||
sprintf(t, "%s %s", dates[i], times[j]);
|
||||
char* t;
|
||||
if (asprintf(&t, "%s %s", dates[i], times[j]) < 0)
|
||||
abort();
|
||||
ts1 = PGTYPEStimestamp_from_asc(t, NULL);
|
||||
text = PGTYPEStimestamp_to_asc(ts1);
|
||||
if (i != 19 || j != 3) /* timestamp as integer or double differ for this case */
|
||||
|
@ -92,12 +92,9 @@ main(void)
|
||||
{
|
||||
for (j = 0; times[j]; j++)
|
||||
{
|
||||
int length = strlen(dates[i])
|
||||
+ 1
|
||||
+ strlen(times[j])
|
||||
+ 1;
|
||||
char* t = malloc(length);
|
||||
sprintf(t, "%s %s", dates[i], times[j]);
|
||||
char* t;
|
||||
if (asprintf(&t, "%s %s", dates[i], times[j]) < 0)
|
||||
abort();
|
||||
ts1 = PGTYPEStimestamp_from_asc(t, NULL);
|
||||
text = PGTYPEStimestamp_to_asc(ts1);
|
||||
if (i != 19 || j != 3) /* timestamp as integer or double differ for this case */
|
||||
|
Reference in New Issue
Block a user