mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +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:
@ -165,12 +165,10 @@ make_absolute_path(const char *path)
|
||||
}
|
||||
}
|
||||
|
||||
new = malloc(strlen(buf) + strlen(path) + 2);
|
||||
if (!new)
|
||||
if (asprintf(&new, "%s/%s", buf, path) < 0)
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
sprintf(new, "%s/%s", buf, path);
|
||||
free(buf);
|
||||
}
|
||||
else
|
||||
@ -1286,9 +1284,7 @@ load_libraries(const char *libraries, const char *gucname, bool restricted)
|
||||
{
|
||||
char *expanded;
|
||||
|
||||
expanded = palloc(strlen("$libdir/plugins/") + strlen(filename) + 1);
|
||||
strcpy(expanded, "$libdir/plugins/");
|
||||
strcat(expanded, filename);
|
||||
expanded = psprintf("$libdir/plugins/%s", filename);
|
||||
pfree(filename);
|
||||
filename = expanded;
|
||||
}
|
||||
|
Reference in New Issue
Block a user