From: Sandro Santilli Date: Tue, 17 Feb 2015 10:03:35 +0000 (+0000) Subject: Remove use of lw_vasprintf from raster X-Git-Tag: 2.2.0rc1~679 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7a9dbb81b658f2e4be62447a7055931733bbea8b;p=postgis Remove use of lw_vasprintf from raster reduces useless heap allocations git-svn-id: http://svn.osgeo.org/postgis/trunk@13218 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_pg/rtpostgis.c b/raster/rt_pg/rtpostgis.c index a4f67c1d9..4ca8802d8 100644 --- a/raster/rt_pg/rtpostgis.c +++ b/raster/rt_pg/rtpostgis.c @@ -148,6 +148,8 @@ PG_MODULE_MAGIC; /* Module load callback */ void _PG_init(void); +#define RT_MSG_MAXLEN 256 + /* ---------------------------------------------------------------- */ /* PostGIS raster GUCs */ /* ---------------------------------------------------------------- */ @@ -472,32 +474,23 @@ rt_pg_free(void *ptr) static void rt_pg_error(const char *fmt, va_list ap) { -#define ERRMSG_MAXLEN 256 - - char errmsg[ERRMSG_MAXLEN+1]; + char errmsg[RT_MSG_MAXLEN+1]; - vsnprintf (errmsg, ERRMSG_MAXLEN, fmt, ap); + vsnprintf (errmsg, RT_MSG_MAXLEN, fmt, ap); - errmsg[ERRMSG_MAXLEN]='\0'; + errmsg[RT_MSG_MAXLEN]='\0'; ereport(ERROR, (errmsg_internal("%s", errmsg))); } static void rt_pg_notice(const char *fmt, va_list ap) { - char *msg; - - /* - * This is a GNU extension. - * Dunno how to handle errors here. - */ - if (!lw_vasprintf (&msg, fmt, ap)) - { - va_end (ap); - return; - } + char msg[RT_MSG_MAXLEN+1]; + + vsnprintf (msg, RT_MSG_MAXLEN, fmt, ap); + + msg[RT_MSG_MAXLEN]='\0'; ereport(NOTICE, (errmsg_internal("%s", msg))); - free(msg); } diff --git a/raster/test/cunit/cu_tester.c b/raster/test/cunit/cu_tester.c index ebc128f2a..c57d9a998 100644 --- a/raster/test/cunit/cu_tester.c +++ b/raster/test/cunit/cu_tester.c @@ -189,18 +189,8 @@ int main(int argc, char *argv[]) * CAUTION: Not stop execution on rterror case !!! */ static void cu_error_reporter(const char *fmt, va_list ap) { - char *msg; - - /** This is a GNU extension. - * Dunno how to handle errors here. - */ - if (!lw_vasprintf (&msg, fmt, ap)) { - va_end (ap); - return; - } - - strncpy(cu_error_msg, msg, MAX_CUNIT_MSG_LENGTH); - rtdealloc(msg); + vsnprintf (cu_error_msg, MAX_CUNIT_MSG_LENGTH, fmt, ap); + cu_error_msg[MAX_CUNIT_MSG_LENGTH]='\0'; } void cu_error_msg_reset() {