<pre style='margin:0'>
Rainer Müller (raimue) pushed a commit to branch master
in repository macports-base.

</pre>
<p><a href="https://github.com/macports/macports-base/commit/52dfc783f6ae22ef0fe2d64680ecc95b7cc88b02">https://github.com/macports/macports-base/commit/52dfc783f6ae22ef0fe2d64680ecc95b7cc88b02</a></p>
<pre style="white-space: pre; background: #F8F8F8">The following commit(s) were added to refs/heads/master by this push:
<span style='display:block; white-space:pre;color:#404040;'>     new 52dfc78  cregistry: Simplify query string with asprintf()
</span>52dfc78 is described below

<span style='display:block; white-space:pre;color:#808000;'>commit 52dfc783f6ae22ef0fe2d64680ecc95b7cc88b02
</span>Author: Rainer Müller <raimue@macports.org>
AuthorDate: Mon Oct 9 15:38:59 2017 +0200

<span style='display:block; white-space:pre;color:#404040;'>    cregistry: Simplify query string with asprintf()
</span><span style='display:block; white-space:pre;color:#404040;'>    
</span><span style='display:block; white-space:pre;color:#404040;'>    This is not as portable as the previous solution with malloc() and
</span><span style='display:block; white-space:pre;color:#404040;'>    snprintf(), but asprintf() is available on all our target platforms and
</span><span style='display:block; white-space:pre;color:#404040;'>    already in use at other places.
</span>---
 src/cregistry/entry.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/entry.c b/src/cregistry/entry.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 9dfc782..f82e885 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/cregistry/entry.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/cregistry/entry.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -30,6 +30,11 @@
</span> #include <config.h>
 #endif
 
<span style='display:block; white-space:pre;background:#e0ffe0;'>+/* required for asprintf(3) on OS X */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#define _DARWIN_C_SOURCE
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* required for asprintf(3) on Linux */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#define _GNU_SOURCE
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> #include "portgroup.h"
 #include "entry.h"
 #include "registry.h"
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -529,20 +534,15 @@ int reg_entry_owner(reg_registry* reg, char* path, int cs, reg_entry** entry,
</span>     int result = 0;
     sqlite3_stmt* stmt = NULL;
     int lower_bound = 0;
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    char *query = NULL;
</span> 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    /* Make sure query_template is as big as the buffer might get. */
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    const char* query_template = "SELECT id FROM registry.files WHERE (actual_path = ? COLLATE NOCASE) AND active";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    const int query_max_size = strlen(query_template) + 1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    char* query = malloc(query_max_size);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    asprintf(&query, "SELECT id FROM registry.files WHERE (actual_path = ? %s) AND active",
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+             cs ? "" : "COLLATE NOCASE");
</span> 
     if (!query) {
         return 0;
     }
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    snprintf(query, query_max_size, "SELECT id FROM registry.files WHERE (actual_path = ? %s) AND active",
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-             cs ? "" : "COLLATE NOCASE");
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span>     if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_text(stmt, 1, path, -1, SQLITE_STATIC)
                 == SQLITE_OK)) {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -592,20 +592,15 @@ int reg_entry_owner(reg_registry* reg, char* path, int cs, reg_entry** entry,
</span> sqlite_int64 reg_entry_owner_id(reg_registry* reg, char* path, int cs) {
     sqlite3_stmt* stmt = NULL;
     sqlite_int64 result = 0;
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    char *query = NULL;
</span> 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    /* Make sure query_template is as big as the buffer might get. */
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    const char* query_template = "SELECT id FROM registry.files WHERE (actual_path = ? COLLATE NOCASE) AND active";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    const int query_max_size = strlen(query_template) + 1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    char* query = malloc(query_max_size);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    asprintf(&query, "SELECT id FROM registry.files WHERE (actual_path = ? %s) AND active",
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+             cs ? "" : "COLLATE NOCASE");
</span> 
     if (!query) {
         return 0;
     }
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    snprintf(query, query_max_size, "SELECT id FROM registry.files WHERE (actual_path = ? %s) AND active",
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-             cs ? "" : "COLLATE NOCASE");
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span>     if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_text(stmt, 1, path, -1, SQLITE_STATIC)
                 == SQLITE_OK)) {
</pre><pre style='margin:0'>

</pre>