Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/makemandb Use sqlite3_mprintf() to generate SQL que...



details:   https://anonhg.NetBSD.org/src/rev/b293f24545fe
branches:  trunk
changeset: 353340:b293f24545fe
user:      abhinav <abhinav%NetBSD.org@localhost>
date:      Sun Apr 30 14:49:26 2017 +0000

description:
Use sqlite3_mprintf() to generate SQL query instead of asprintf.

diffstat:

 usr.sbin/makemandb/apropos-utils.c |  30 +++++++++++++++++-------------
 1 files changed, 17 insertions(+), 13 deletions(-)

diffs (66 lines):

diff -r 205b2b2a0a3a -r b293f24545fe usr.sbin/makemandb/apropos-utils.c
--- a/usr.sbin/makemandb/apropos-utils.c        Sun Apr 30 13:45:06 2017 +0000
+++ b/usr.sbin/makemandb/apropos-utils.c        Sun Apr 30 14:49:26 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: apropos-utils.c,v 1.32 2017/04/27 08:02:24 abhinav Exp $       */
+/*     $NetBSD: apropos-utils.c,v 1.33 2017/04/30 14:49:26 abhinav Exp $       */
 /*-
  * Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
  * All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: apropos-utils.c,v 1.32 2017/04/27 08:02:24 abhinav Exp $");
+__RCSID("$NetBSD: apropos-utils.c,v 1.33 2017/04/30 14:49:26 abhinav Exp $");
 
 #include <sys/queue.h>
 #include <sys/stat.h>
@@ -503,12 +503,21 @@
        char *section_clause = NULL;
        char *limit_clause = NULL;
        char *machine_clause = NULL;
-       char *query;
+       char *query = NULL;
+
+       if (args->machine) {
+               machine_clause = sqlite3_mprintf("AND mandb.machine=%Q", args->machine);
+               if (machine_clause == NULL)
+                       goto RETURN;
+       }
 
-       if (args->machine)
-               easprintf(&machine_clause, "AND mandb.machine = \'%s\' ",
-                   args->machine);
-
+       if (args->nrec >= 0) {
+               /* Use the provided number of records and offset */
+               limit_clause = sqlite3_mprintf(" LIMIT %d OFFSET %d",
+                   args->nrec, args->offset);
+               if (limit_clause == NULL)
+                       goto RETURN;
+       }
 
        /* We want to build a query of the form: "select x,y,z from mandb where
         * mandb match :query [AND (section LIKE '1' OR section LIKE '2' OR...)]
@@ -554,12 +563,6 @@
                }
        }
 
-       if (args->nrec >= 0) {
-               /* Use the provided number of records and offset */
-               easprintf(&limit_clause, " LIMIT %d OFFSET %d",
-                   args->nrec, args->offset);
-       }
-
        if (snippet_args == NULL) {
                default_snippet_args[0] = "";
                default_snippet_args[1] = "";
@@ -623,6 +626,7 @@
                limit_clause ? limit_clause : "");
        }
 
+RETURN:
        free(machine_clause);
        free(section_clause);
        free(limit_clause);



Home | Main Index | Thread Index | Old Index