]> granicus.if.org Git - postgis/commitdiff
Remove use of lw_vasprintf from raster
authorSandro Santilli <strk@keybit.net>
Tue, 17 Feb 2015 10:03:35 +0000 (10:03 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 17 Feb 2015 10:03:35 +0000 (10:03 +0000)
reduces useless heap allocations

git-svn-id: http://svn.osgeo.org/postgis/trunk@13218 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_pg/rtpostgis.c
raster/test/cunit/cu_tester.c

index a4f67c1d90f38a6d37dde2033935935c19efb3a0..4ca8802d840c2d0b80b8de1b78536883d5256932 100644 (file)
@@ -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);
 }
 
 
index ebc128f2a0244829c23a247ba6140810fd884ac3..c57d9a998e7b14fc69bd686343cd8e8c5bbd1e1d 100644 (file)
@@ -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() {