Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/makemandb Avoid dereferencing pointer at multiple p...



details:   https://anonhg.NetBSD.org/src/rev/76fc05414f36
branches:  trunk
changeset: 823658:76fc05414f36
user:      abhinav <abhinav%NetBSD.org@localhost>
date:      Mon May 01 06:56:00 2017 +0000

description:
Avoid dereferencing pointer at multiple places, instead use a local variable.

diffstat:

 usr.sbin/makemandb/makemandb.c |  20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diffs (67 lines):

diff -r a58358bfbfa8 -r 76fc05414f36 usr.sbin/makemandb/makemandb.c
--- a/usr.sbin/makemandb/makemandb.c    Mon May 01 06:43:56 2017 +0000
+++ b/usr.sbin/makemandb/makemandb.c    Mon May 01 06:56:00 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makemandb.c,v 1.52 2017/05/01 06:43:56 abhinav Exp $   */
+/*     $NetBSD: makemandb.c,v 1.53 2017/05/01 06:56:00 abhinav Exp $   */
 /*
  * Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
  * Copyright (c) 2011 Kristaps Dzonsons <kristaps%bsd.lv@localhost>
@@ -17,7 +17,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: makemandb.c,v 1.52 2017/05/01 06:43:56 abhinav Exp $");
+__RCSID("$NetBSD: makemandb.c,v 1.53 2017/05/01 06:56:00 abhinav Exp $");
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -1832,16 +1832,17 @@
  *  1: If the hash exists in the database.
  */
 static int
-check_md5(const char *file, sqlite3 *db, char **md5sum, void *buf, size_t buflen)
+check_md5(const char *file, sqlite3 *db, char **md5, void *buf, size_t buflen)
 {
        int rc = 0;
        int idx = -1;
        char *sqlstr = NULL;
+       char *mymd5;
        sqlite3_stmt *stmt = NULL;
+       *md5 = NULL;
 
        assert(file != NULL);
-       *md5sum = MD5Data(buf, buflen, NULL);
-       if (*md5sum == NULL) {
+       if ((mymd5 = MD5Data(buf, buflen, NULL)) == NULL) {
                if (mflags.verbosity)
                        warn("md5 failed: %s", file);
                return -1;
@@ -1851,23 +1852,22 @@
        rc = sqlite3_prepare_v2(db, sqlstr, -1, &stmt, NULL);
        if (rc != SQLITE_OK) {
                free(sqlstr);
-               free(*md5sum);
-               *md5sum = NULL;
+               free(mymd5);
                return -1;
        }
 
        idx = sqlite3_bind_parameter_index(stmt, ":md5_hash");
-       rc = sqlite3_bind_text(stmt, idx, *md5sum, -1, NULL);
+       rc = sqlite3_bind_text(stmt, idx, mymd5, -1, NULL);
        if (rc != SQLITE_OK) {
                if (mflags.verbosity)
                        warnx("%s", sqlite3_errmsg(db));
                sqlite3_finalize(stmt);
                free(sqlstr);
-               free(*md5sum);
-               *md5sum = NULL;
+               free(mymd5);
                return -1;
        }
 
+       *md5 = mymd5;
        if (sqlite3_step(stmt) == SQLITE_ROW) {
                sqlite3_finalize(stmt);
                free(sqlstr);



Home | Main Index | Thread Index | Old Index